【问题标题】:Buttons not displaying in linear layout按钮未以线性布局显示
【发布时间】:2011-02-02 10:53:37
【问题描述】:

大家好 我的需要是按钮必须显示在底部,所以我的代码为

<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:orientation="vertical"
  android:padding="12dip">

  <ListView
      android:id="@+id/list_multiselectable"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:layout_gravity="center_vertical">
  </ListView>
<LinearLayout android:orientation="horizontal"           

     android:background="@android:drawable/bottom_bar"
    android:paddingLeft="4.0dip" android:paddingTop="5.0dip"
    android:paddingRight="4.0dip" android:paddingBottom="1.0dip"
    android:layout_width="fill_parent" android:layout_height="wrap_content"
    android:layout_alignParentBottom="true">

    my buttons code here
</LinearLayout>
  </LinearLayout> 

但是当列表中的项目较少时(直到列表视图的滚动条未启用),按钮可见,但是当列表中的项目较多时,按钮不可见,虽然我将列表项滚动到最后一行,但在最后一个按钮不显示。我该如何解决。

谢谢!

【问题讨论】:

    标签: android android-widget android-layout


    【解决方案1】:

    LinearLayoutListView 提供了它需要的所有空间,因为它按顺序考虑其子代,而不考虑后面的那些。

    我的建议是使用RelativeLayout。

    <RelativeLayout ...>
      <ListView ...
               android:id="@+id/list"
               android:layout_alignParentTop="true"/>
      <LinearLayout ...
               android:layout_below="@id/list"
               android:layout_alignParentBottom="true">
         ...buttons...
      </LinearLayout>
    </RelativeLayout>
    

    【讨论】:

    • 您能否在列表视图和线性布局的属性中添加更多详细信息。
    【解决方案2】:

    我不确定。但您可以尝试设置列表视图的权重。

    <ListView
          android:id="@+id/list_multiselectable"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:layout_weight="1"
          android:layout_gravity="center_vertical">
      </ListView>
    

    【讨论】:

      【解决方案3】:

      可以设置listview的最小高度 例如320*480 列表视图高度 = 430 按钮的布局高度 = 50

      【讨论】:

        猜你喜欢
        • 2021-05-03
        • 2018-10-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-10-09
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多