【问题标题】:Two ListViews and One Button两个 ListView 和一个按钮
【发布时间】:2012-11-09 12:31:50
【问题描述】:

我正在做一个 android 应用程序,我想将布局分成 3 个部分,如下所示:

但现在按钮在第二个列表视图上方,但在屏幕底部,我不知道为什么。

我不知道是否必须使用 relativeLayout 或 linearLayout 来包含列表视图,并且文本在此内部或 relativelayout/linearLayout 外部,最后一个按钮是什么?

这是我的代码:

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
       android:layout_width="fill_parent"
       android:layout_height="fill_parent"
       android:orientation="vertical" >

   <TextView android:id="@+id/imageSelected"
          android:text="@string/imgSelected"
          android:layout_width="wrap_content"
              android:layout_height="fill_parent"
              android:layout_marginBottom="3dip"/>

   <LinearLayout 
     android:id="@+id/linearLayoutImagenes"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_alignParentTop="true"
     android:layout_below="@+id/imageSelected" >

   <ListView
      android:id="@+id/listaFusionPhotos"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent" 
      />

   </LinearLayout >

    <TextView android:id="@+id/nameSelected"
          android:text="@string/namSelected"
          android:layout_width="wrap_content"
          android:layout_height="fill_parent"
          android:layout_below="@+id/linearLayoutImagenes"
          android:layout_marginBottom="3dip"/>


<LinearLayout  
  android:id="@+id/linearLayoutNombres"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignParentTop="true"
      android:layout_below="@+id/nameSelected"
      >

    <ListView
       android:id="@+id/listaFusionNombres"
       android:layout_width="fill_parent"
       android:layout_height="fill_parent"/>

   </LinearLayout >

   <Button
      android:id="@+id/fusion"
      android:layout_width="160dip"
      android:layout_height="wrap_content"
      android:layout_below="@+id/linearLayoutNombres"
      android:layout_marginTop="3dip"
      android:text="Fusionar" 
      android:onClick="Mostrar_Registrados"
      android:layout_alignParentBottom="true"/>



</RelativeLayout>

【问题讨论】:

  • 为什么不在 ScrollView 中使用相对布局

标签: android listview button scroll


【解决方案1】:

试试这个。这看起来和图片一模一样。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="11" >

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="0dp"
    android:text="Medium Text"
    android:textAppearance="?android:attr/textAppearanceMedium" 
    android:layout_weight="1"/>

<ListView
    android:id="@+id/listView1"
    android:layout_width="fill_parent"
    android:layout_height="0dp" 
    android:layout_weight="4">
</ListView>

<TextView
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
   android:layout_height="0dp"
    android:layout_weight="1"
    android:text="Medium Text"
    android:textAppearance="?android:attr/textAppearanceMedium" />

<ListView
    android:id="@+id/listView2"
    android:layout_width="fill_parent"
    android:layout_height="0dp" 
    android:layout_weight="4">
</ListView>

<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:text="Button" />

</LinearLayout>

【讨论】:

    【解决方案2】:
    <LinearLayout  
         android:id="@+id/linearLayoutNombres"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignParentTop="true"
          android:layout_below="@+id/nameSelected"
          android:layout_above="@+id/fusion" // "line added"
    >
        <Button
          android:id="@+id/fusion"
          android:layout_width="160dip"
          android:layout_height="wrap_content"
          android:layout_below="@+id/linearLayoutNombres" --> "remove this line"
          android:layout_marginTop="3dip"
          android:text="Fusionar" 
          android:onClick="Mostrar_Registrados"
          android:layout_alignParentBottom="true"/>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-01-24
      • 1970-01-01
      • 2015-09-24
      • 2015-04-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多