Android布局问题
我试图创建一个简单的布局,但找不到一个支撑方法来实现它。布局应该有3个元素:TeXVIEW在顶部,中间的EditText(带有ScLoVIEW)和底部的按钮。 我制定了以下代码:Android布局问题,android,layout,Android,Layout,我试图创建一个简单的布局,但找不到一个支撑方法来实现它。布局应该有3个元素:TeXVIEW在顶部,中间的EditText(带有ScLoVIEW)和底部的按钮。 我制定了以下代码: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:weightSum="1" android
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:weightSum="1"
android:orientation="vertical"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<LinearLayout android:layout_weight="0.97"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:id="@+id/linearLayout18"
android:orientation="vertical">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Text:"
android:gravity="center_vertical"/>
<ScrollView android:layout_width="fill_parent"
android:layout_height="fill_parent">
<EditText
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/txtMessage"
android:text=""/>
</ScrollView>
</LinearLayout>
<LinearLayout
android:layout_weight="0.03"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:id="@+id/linearLayout1"
android:orientation="vertical">
<Button
android:text="Next"
android:id="@+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
</LinearLayout>
但它给了我这样的布局:正如您所看到的,问题是EditText不会占用所有可用的垂直空间(一直到按钮)。如何解决这个问题?只需在
滚动视图中使用android:fillViewport=“true”
试试相对性而不是线性这里是示例代码
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<RelativeLayout android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:id="@+id/linearLayout18" android:layout_alignParentTop="true">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Text:"
android:id="@+id/textMessage"
android:gravity="center_vertical" android:layout_alignParentTop="true"/>
<ScrollView android:layout_width="fill_parent"
android:layout_below="@+id/textMessage" android:layout_above="@+id/button1" android:scrollbars="horizontal|vertical" android:layout_height="fill_parent" android:fillViewport="true">
<EditText
android:id="@+id/txtMessage"
android:text="" android:layout_height="fill_parent" android:layout_width="fill_parent"/>
</ScrollView>
<Button
android:text="Next"
android:id="@+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
</RelativeLayout>
试试这个……这太完美了……我在我的android studio中对它进行了测试……这和你想要的布局一样
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Text:"
android:id="@+id/textview1"
android:layout_alignParentTop="true"/>
<ScrollView android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
android:layout_above="@id/btn"
android:layout_below="@id/textview1">
<EditText
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:id="@+id/txtMessage"
android:text=""/>
</ScrollView>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/txtMessage"
android:id="@+id/btn"
android:text="Next"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
两个相同(且正确)的答案。我选择了你的-你先回答:)简单高效的解决方案,谢谢!:)好吧,添加android:fillViewport=“true”解决了问题,为什么我要使用“相对布局”?