【发布时间】:2020-03-15 11:31:37
【问题描述】:
考虑当一个人想要一个线性布局中的视图来填充布局中剩余的空白空间的情况;然后将这个视图的权重设置为 1,而其他视图的权重为 0。
有没有办法对父视图组中的子视图组做类似的事情。
例如,考虑下面我的 xml:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:fillViewport="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/coffee"
android:scaleType="centerCrop"
android:alpha="0.7"/>
<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
android:gravity="center"
android:text="@string/bus_title"
android:textColor="#FFFF"
android:textSize="24dp"
android:textStyle="bold|italic" />
<TextView
android:id="@+id/about_heading"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/title"
android:layout_marginBottom="16dp"
android:gravity="center"
android:text="About Us"
android:textColor="#FFFF"
android:textSize="16sp"
android:textStyle="bold|italic" />
<TextView
android:id="@+id/about_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/about_heading"
android:layout_marginBottom="16dp"
android:gravity="center"
android:text="@string/bus_description"
android:textColor="#FFFF"
android:textSize="16sp"
android:textStyle="bold" />
<TextView
android:id="@+id/opening_hours_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/about_text"
android:layout_marginBottom="16dp"
android:gravity="center"
android:text="@string/opening_hours_header"
android:textColor="#FFFF"
android:textSize="16sp"
android:textStyle="bold|italic" />
<TextView
android:id="@+id/opening_times"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/opening_hours_header"
android:layout_marginBottom="16dp"
android:gravity="center"
android:text="@string/opening_hours"
android:textColor="#FFFF"
android:textSize="16sp"
android:textStyle="bold" />
<TextView
android:id="@+id/Contact_Us_heading"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/opening_times"
android:layout_marginBottom="16dp"
android:gravity="center"
android:text="@string/Contact_heading"
android:textColor="#FFFF"
android:textSize="16sp"
android:textStyle="bold|italic" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="200dp"
android:orientation="vertical"
android:layout_below="@id/Contact_Us_heading">
<EditText
android:id="@+id/email_field"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#80E0E0E0"
android:gravity="top"
android:inputType="text"
android:hint="Type a message here..."
android:layout_below="@id/Contact_Us_heading"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:text="SEND" />
</LinearLayout>
</RelativeLayout>
</ScrollView>
你会看到我在几个 textViews 下面插入了一个子 LinearLayout。
我希望线性布局填充相对布局下方的“剩余空间”,就像 editText 视图填充线性布局的其余部分一样。
有什么办法吗?
【问题讨论】:
标签: android xml android-layout android-linearlayout android-relativelayout