1

我的父布局是线性布局,在里面我试图添加两个线性布局。由于某些原因。唯一会显示的布局是带有两个按钮的线性布局,另一个永远不会出现....有什么建议吗?

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:orientation="vertical">
<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="140dp"
    android:layout_weight="2"
    android:orientation="vertical">
    <TextView
            android:id="@+id/dynamic_actionsText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1" 
            android:text="Text"/>
    <Spinner
            android:id="@+id/dynamic_actionsSpinner"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1" />
</LinearLayout>
<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="240dp"
    android:layout_weight="2"
    android:orientation="vertical">
    <Button android:id="@+id/dynamic_btnSubmit"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1.0"
            android:visibility="gone"/>
    <Button android:id="@+id/dynamic_btnSave"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1.0"
            android:visibility="gone"/>
</LinearLayout>
</LinearLayout>
4

2 回答 2

0
any suggestions?

建议:

1 - 将方向垂直设置为两个 LinearLayout 的父级.....

2- 从 dynamic_btnSubmit 和 dynamic_btnSave 中删除 android:visibility="gone"

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="140dp"
        android:layout_weight="2"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/dynamic_actionsText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Text" />

        <Spinner
            android:id="@+id/dynamic_actionsSpinner"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="240dp"
        android:layout_weight="2"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/dynamic_btnSubmit"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1.0" />

        <Button
            android:id="@+id/dynamic_btnSave"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1.0" />
    </LinearLayout>

</LinearLayout>

在此处输入图像描述

于 2012-06-26T15:13:59.600 回答
0

首先删除可见性消失(如 Dheeresh 所述)

现在,按钮的 android:layout_height="wrap_content" 是问题所在。

由于按钮中没有文本内容,因此它们的高度本质上为 = 0(wrap_content 的行为)

在两个按钮中添加一个属性为 android:text="Hi"。你现在应该可以看到它们了。

如果您打算动态执行整个操作,请执行以下操作,

Button btnSubmit=(Button) findViewById(R.id.dynamic_btnSubmit);
btnSubmit.setText("Submit");
Button btnSave=(Button) findViewById(R.id.dynamic_btnSave);
btnSave.setText("Save");
btnSubmit.setVisibility(VIEW.VISIBLE);
btnSave.setVisibility(VIEW.VISIBLE);
于 2012-06-26T15:48:06.470 回答