【问题标题】:buttons disappearing from a linear layout按钮从线性布局中消失
【发布时间】:2016-06-10 09:44:20
【问题描述】:

我有一个复杂的线性布局,带有一些按钮和编辑文本:

        <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:gravity="top|center_horizontal"
        android:orientation="vertical"
        android:weightSum="1"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_marginBottom="400dp">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="40dp"
            android:layout_marginTop="0dp"
            android:text="@string/stop"
            android:textSize="18dp"
            android:textStyle="bold" />



        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal">
        <EditText
            android:id="@+id/text"
            android:hint="@string/hint"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/choose"
            android:layout_alignParentLeft="true"
            android:minWidth="150dp"
            android:textSize="10sp"/>
        <Button
            android:id="@+id/text2"
            android:hint="@string/favourites"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/choose"
            android:layout_alignParentRight="true"
            android:layout_toRightOf="@+id/text"
            android:textSize="10sp"
            />
            <Button
                android:id="@+id/text3"
                android:hint="@string/clean"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/choose"
                android:layout_alignParentRight="true"
                android:layout_toRightOf="@+id/text"
                android:textSize="10sp"
                />
        </LinearLayout>

        <Button
            android:id="@+id/button"
            android:text="@string/request"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/text2"
            android:onClick="lookUp"
            android:textSize="12sp"
            />


        <ScrollView
            android:id="@+id/scrollView1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="#3d455b"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/button">

            <HorizontalScrollView
                android:id="@+id/hscrll1"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content" >
                <RelativeLayout
                    android:id="@+id/RelativeLayout1"
                    android:layout_width="fill_parent"
                    android:layout_gravity="left"
                    android:layout_height="fill_parent"
                    android:orientation="vertical" >


                    <TableLayout
                        android:id="@+id/table_main"
                        android:layout_width="fill_parent"
                        android:layout_height="fill_parent"
                        android:layout_centerHorizontal="false"
                        android:stretchColumns="2">
                    </TableLayout>
                </RelativeLayout>
            </HorizontalScrollView>
        </ScrollView>

    </LinearLayout>

一切看起来都应该在大屏幕(平板电脑)上:我有第一行带有编辑文本和两个按钮,在下面的行中我有另一个按钮,在它下面我有滚动视图(带有表格) . 当我切换到普通屏幕(智能手机)时,只出现第一行,其余的不可见。 解决办法是什么?

【问题讨论】:

  • 您的布局足够大。它不会进入手机屏幕。你应该把整个布局放到滚动视图中
  • 你的意思是添加一个围绕线性布局的滚动视图吗?
  • 是的,不是介于两者之间的整个布局的父级
  • android:layout_marginBottom="400dp" 它应该基于屏幕密度

标签: android xml android-edittext textview tableview


【解决方案1】:

在小屏设备上你设置的margin有问题,试试 从您的ParentLayout 中删除android:layout_marginBottom="400dp" 并根据他们管理您的Layout

【讨论】:

  • @helius83 总是 wlc
【解决方案2】:

在第二个线性布局(具有水平方向)处,所有视图都具有匹配的父宽度,导致它们都不可见。我想这就是你想要的:

`

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
    <EditText
        android:id="@+id/text"
        android:hint="@string/hint"
        android:layout_width="0dp"
        android:layout_weight = "1"
        android:layout_height="wrap_content"

        android:minWidth="150dp"
        android:textSize="10sp"/>
    <Button
        android:id="@+id/text2"
        android:hint="@string/favourites"
        android:layout_width="0dp"
        androidlayout_weight = "1"
        android:layout_height="wrap_content"

        android:textSize="10sp"
        />
        <Button
            android:id="@+id/text3"
            android:hint="@string/clean"
            android:layout_width="0dp"
            android:layout_weight = "1"
            android:layout_height="wrap_content"
            android:textSize="10sp"
            />
 </LinearLayout>

`

【讨论】:

    猜你喜欢
    • 2011-09-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-20
    • 1970-01-01
    • 2015-08-11
    • 2011-01-31
    相关资源
    最近更新 更多