[英]Linear Layout - Buttons Disappear
考虑以下XML布局,其中包含一个可滚动的TextView和其下方的两个Button。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<TextView
android:id="@+id/description"
android:scrollbars = "vertical"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button1"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button2"
/>
</LinearLayout>
</LinearLayout>
TextView是动态更新的。 如果TextView内容适合在屏幕上,则这些按钮会很好地显示。 但是,一旦TextView内容超过屏幕大小以使用滚动条,底部的按钮就会消失。
如何确保按钮始终显示,滚动条或不显示?
尝试设置maxHeight:
android:maxHeight="480dp"
检查屏幕尺寸并动态设置maxHeight
将Layout weightSum =“ 2”设置为线性布局,将每个按钮的layout_weight设置为1
android:weightSum="2" // to the layout
android:layout_weight="1" // to each the button
另外,您的android:orientation =“ horizontal”是水平的 ,这是默认设置,也许您想要垂直 ,(只是说)...
编辑删除滚动条属性,并将textView包装在ScrollView中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.