简体   繁体   English

线性布局-按钮消失

[英]Linear Layout - Buttons Disappear

Consider the following XML layout with one scrollable TextView and two Buttons below it. 考虑以下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>

The TextView is updated dynamically. TextView是动态更新的。 The buttons show up nicely if the TextView content fits on the screen. 如果TextView内容适合在屏幕上,则这些按钮会很好地显示。 However as soon as the TextView content exceed screen size to use a scrollbar, the bottom buttons disappear. 但是,一旦TextView内容超过屏幕大小以使用滚动条,底部的按钮就会消失。

How to ensure that buttons show up always, scrollbar or no scrollbar ? 如何确保按钮始终显示,滚动条或不显示?

Try setting maxHeight: 尝试设置maxHeight:

android:maxHeight="480dp"

check the screen size and dynamically set the maxHeight 检查屏幕尺寸并动态设置maxHeight

set Layout weightSum="2" to the linear layout, layout_weight to each button to 1 将Layout weightSum =“ 2”设置为线性布局,将每个按钮的layout_weight设置为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)... 另外,您的android:orientation =“ horizo​​ntal”水平的 ,这是默认设置,也许您想要垂直 ,(只是说)...

EDIT Remove the scrollbar attributes and wrap the textView in a ScrollView. 编辑删除滚动条属性,并将textView包装在ScrollView中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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