gpt4 book ai didi

Android match_parent 未按预期工作

转载 作者:太空宇宙 更新时间:2023-11-03 11:55:25 26 4
gpt4 key购买 nike

在我的布局文件中,我使用根 ScrollView 和子 LinearLayout

我对此进行了搜索,但没有得到帮助。我在父 View 和 subview 中设置了 ma​​tch_parent

但是 subview 有问题。

subview 不像父 View 那样填充。

这是图片和xml代码。

enter image description here

布局文件。

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:CustomTextView="http://schemas.android.com/apk/res-auto"
xmlns:CustomEditTextView="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#D3D6DB"
android:orientation="vertical"
tools:context=".tabs.MyTravelTab" >

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/card_background_new"
android:orientation="vertical" >

<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical" >

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp" >

<LinearLayout
android:layout_width="0dp"
android:layout_height="@dimen/field_height"
android:layout_weight="0.4"
android:gravity="left|center_vertical" >

<com.mymv.controls.CustomTextView
android:id="@+id/textGPS"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
CustomTextView:typeface="Roboto-Regular.ttf"
android:text="ABC"
android:textColor="@color/black"
android:textSize="12sp" />

<ToggleButton
android:id="@+id/gps_toggle"
android:layout_width="wrap_content"
android:layout_height="24dp"
android:layout_margin="5dp"
android:background="@drawable/gps_custom_toggle"
android:checked="false"
android:textOff=""
android:textOn="" />

<com.mymv.controls.CustomTextView
android:id="@+id/textManual"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
CustomTextView:typeface="Roboto-Regular.ttf"
android:text="DEF"
android:textColor="@color/black"
android:textSize="11sp" />
</LinearLayout>

<Spinner
android:id="@+id/spinnerPurposeOfJourney"
android:layout_width="0dp"
android:layout_height="@dimen/field_height"
android:layout_weight="0.6"
android:background="@drawable/dropdown_black_border"
android:entries="@array/purpose_of_journey" />
</LinearLayout>

<LinearLayout
android:id="@+id/gpsLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:visibility="gone" >

<LinearLayout
android:id="@+id/startGPSBtn"
android:layout_width="0dp"
android:layout_height="@dimen/field_height"
android:layout_weight="0.5"
android:background="@drawable/textview_green_drawable_left_curve_selector"
android:gravity="center" >

<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/gps" />

<com.mymv.controls.CustomTextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
CustomTextView:typeface="Roboto-Regular.ttf"
android:text="START GPS"
android:textColor="@color/white" />
</LinearLayout>

<LinearLayout
android:id="@+id/endGPSBtn"
android:layout_width="0dp"
android:layout_height="@dimen/field_height"
android:layout_weight="0.5"
android:background="@drawable/textview_red_drawable_right_curve_selector"
android:gravity="center" >

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/end_flag" />

<com.mymv.controls.CustomTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
CustomTextView:typeface="Roboto-Regular.ttf"
android:text="END GPS"
android:textColor="@color/white" />
</LinearLayout>
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="10dp" >

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center" >

<com.mymv.controls.CustomTextView
android:layout_width="0dp"
android:layout_height="@dimen/field_height"
android:layout_weight="@integer/layout_weight_textview"
CustomTextView:typeface="Roboto-Bold.ttf"
android:background="@drawable/textview_gray_drawable"
android:gravity="center_vertical"
android:padding="5dp"
android:text="DATA"
android:textColor="@color/gray" />

<com.mymv.controls.CustomTextView
android:id="@+id/edtTxtDate"
android:layout_width="0dp"
android:layout_height="@dimen/field_height"
android:layout_marginLeft="-1dp"
android:layout_weight="@integer/layout_weight_edittext"
CustomTextView:typeface="Roboto-Regular.ttf"
android:background="@drawable/edittext_drawable_right_curv_selector"
android:gravity="center_vertical"
android:hint="DATA"
android:padding="5dp"
android:singleLine="true"
android:textColor="@color/black"
android:textColorHint="@color/gray"
android:textSize="15dp" />
</LinearLayout>

<LinearLayout
android:id="@+id/manualLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="visible" >

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="center" >

<com.mymv.controls.CustomTextView
android:layout_width="0dp"
android:layout_height="@dimen/field_height"
android:layout_weight="@integer/layout_weight_textview"
CustomTextView:typeface="Roboto-Bold.ttf"
android:background="@drawable/textview_gray_drawable"
android:gravity="center_vertical"
android:padding="5dp"
android:text="DATA"
android:textColor="@color/gray" />

<com.mymv.controls.CustomEditTextView
android:id="@+id/edtTxtStartOdometer"
android:layout_width="0dp"
android:layout_height="@dimen/field_height"
android:layout_marginLeft="-1dp"
android:layout_weight="@integer/layout_weight_edittext"
CustomTextView:typeface="Roboto-Regular.ttf"
android:background="@drawable/edittext_drawable_right_curv_selector"
android:focusable="false"
android:gravity="center_vertical"
android:hint="DATA"
android:inputType="number"
android:maxLength="6"
android:padding="5dp"
android:singleLine="true"
android:textColor="@color/black"
android:textColorHint="@color/gray"
android:textSize="15dp" />
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="center" >

<com.mymv.controls.CustomTextView
android:layout_width="0dp"
android:layout_height="@dimen/field_height"
android:layout_weight="@integer/layout_weight_textview"
CustomTextView:typeface="Roboto-Bold.ttf"
android:background="@drawable/textview_gray_drawable"
android:gravity="center_vertical"
android:padding="5dp"
android:text="DATA"
android:textColor="@color/gray" />

<com.mymv.controls.CustomEditTextView
android:id="@+id/edtTxtEndOdometer"
android:layout_width="0dp"
android:layout_height="@dimen/field_height"
android:layout_marginLeft="-1dp"
android:layout_weight="@integer/layout_weight_edittext"
CustomEditTextView:typeface="Roboto-Regular.ttf"
android:background="@drawable/edittext_drawable_right_curv_selector"
android:focusable="false"
android:gravity="center_vertical"
android:hint="DATA"
android:inputType="number"
android:maxLength="6"
android:padding="5dp"
android:singleLine="true"
android:textColor="@color/black"
android:textColorHint="@color/gray"
android:textSize="15dp" />
</LinearLayout>
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="center" >

<com.mymv.controls.CustomTextView
android:layout_width="0dp"
android:layout_height="@dimen/field_height"
android:layout_weight="@integer/layout_weight_textview"
CustomTextView:typeface="Roboto-Bold.ttf"
android:background="@drawable/textview_gray_drawable"
android:gravity="center_vertical"
android:padding="5dp"
android:text="DATA"
android:textColor="@color/gray" />

<com.mymv.controls.CustomEditTextView
android:id="@+id/edtTxtStartLocation"
android:layout_width="0dp"
android:layout_height="@dimen/field_height"
android:layout_marginLeft="-1dp"
android:layout_weight="@integer/layout_weight_edittext"
CustomEditTextView:typeface="Roboto-Regular.ttf"
android:background="@drawable/edittext_drawable_right_curv_selector"
android:focusable="false"
android:gravity="center_vertical"
android:hint="DATA"
android:maxLength="100"
android:padding="5dp"
android:singleLine="true"
android:textColor="@color/black"
android:textColorHint="@color/gray"
android:textSize="15dp" />
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="center" >

<com.mymv.controls.CustomTextView
android:layout_width="0dp"
android:layout_height="@dimen/field_height"
android:layout_weight="@integer/layout_weight_textview"
CustomTextView:typeface="Roboto-Bold.ttf"
android:background="@drawable/textview_gray_drawable"
android:gravity="center_vertical"
android:padding="5dp"
android:text="DATA"
android:textColor="@color/gray" />

<com.mymv.controls.CustomEditTextView
android:id="@+id/edtTxtEndLocation"
android:layout_width="0dp"
android:layout_height="@dimen/field_height"
android:layout_marginLeft="-1dp"
android:layout_weight="@integer/layout_weight_edittext"
CustomEditTextView:typeface="Roboto-Regular.ttf"
android:background="@drawable/edittext_drawable_right_curv_selector"
android:focusable="false"
android:gravity="center_vertical"
android:hint="DATA"
android:maxLength="100"
android:padding="5dp"
android:singleLine="true"
android:textColor="@color/black"
android:textColorHint="@color/gray"
android:textSize="15dp" />
</LinearLayout>

<Button
android:id="@+id/btnRecord"
android:layout_width="match_parent"
android:layout_height="@dimen/field_height"
android:layout_marginTop="10dp"
android:background="@drawable/button_blue_border"
android:text="Button"
android:textColor="@color/white"
android:textSize="15dp" />
</LinearLayout>
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >

<Button
android:id="@+id/viewUsage"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="0.5"
android:background="@drawable/button_background_yellow"
android:padding="10dp"
android:text="Button1"
android:textColor="@color/black" />

<Button
android:id="@+id/viewTravelHistory"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="0.5"
android:background="@drawable/button_background_blue"
android:padding="10dp"
android:text="Button2"
android:textColor="@color/white" />
</LinearLayout>
</LinearLayout>

</ScrollView>

最佳答案

在 ScrollView 中尝试 android:fillViewport="true"

关于Android match_parent 未按预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37856835/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com