[英]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.