简体   繁体   中英

Linear Layout - Buttons Disappear

Consider the following XML layout with one scrollable TextView and two Buttons below it.

<?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>

The TextView is updated dynamically. The buttons show up nicely if the TextView content fits on the screen. However as soon as the TextView content exceed screen size to use a scrollbar, the bottom buttons disappear.

How to ensure that buttons show up always, scrollbar or no scrollbar ?

Try setting maxHeight:

android:maxHeight="480dp"

check the screen size and dynamically set the maxHeight

set Layout weightSum="2" to the linear layout, layout_weight to each button to 1

android:weightSum="2" // to the layout

android:layout_weight="1" // to each the button

Also your android:orientation="horizontal" is horizontal , which is default, maybe you want to be vertical , (just saying)...

EDIT Remove the scrollbar attributes and wrap the textView in a ScrollView.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM