【问题标题】:having problems with the xml layout, multiple relative layouts are being createdxml布局有问题,正在创建多个相关布局
【发布时间】:2011-05-12 17:34:21
【问题描述】:

我有一个添加到 abc.xml 和 textview id 标签的数组字符串

this.setListAdapter(new ArrayAdapter<String>(this, R.layout.abc,R.id.label, days));

在我的 abc.xml 文件中,我有一个相对布局来显示导航栏,仅显示一次。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#4C4646"
    >
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/RelativeLayout02" android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="#3E3D3D"
    android:paddingRight="3dp"
    android:paddingLeft="3dp"
    >
     <Button android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:id="@+id/back_listing"
        android:background="@drawable/android_back_button"
        android:layout_marginTop="6dp">
      </Button>

<TextView android:id="@+id/search_label" 
    android:layout_width="fill_parent"
    android:layout_height="45dp" 
    android:layout_toRightOf="@+id/back_listing" 
    android:layout_toLeftOf="@+id/search_submit"
    android:textSize="20px"
            android:text="Nav Bar"
    android:layout_marginTop="7dp"
    android:layout_marginLeft="45dp"
    android:layout_gravity="right"
    android:textStyle="bold"/>
    />


<Button android:layout_width="wrap_content"
    android:layout_height="wrap_content" android:id="@+id/search_submit"
    android:layout_alignParentRight="true"
    android:background="@drawable/android_forward_button"
    android:layout_marginTop="6dp"

    >
</Button>
</RelativeLayout>

然后

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10px"
android:textSize="15px" 
android:id="@+id/label"
>

用数组列表填充文本视图

但我遇到的问题是导航栏显示在顶部,然后是我的数组列表中的第一项,然后导航栏再次出现,然后是我的数组列表中的第二项,然后是导航栏,这种情况一直持续到最后的数组列表。同样,导航栏与我的数组列表处于循环中。现在,当我将相关布局(导航栏)的内容从文本视图中移除时,它会完美显示,但我当然希望导航栏在顶部显示一次。

【问题讨论】:

    标签: android android-layout android-relativelayout


    【解决方案1】:

    你需要分开这个:

    <TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="10px"
    android:textSize="15px" 
    android:id="@+id/label"
    >
    

    到一个不同的 xml 文件中,也许将其命名为 row.xml 然后将该文件与您的适配器一起使用。如果您希望导航栏位于顶部,请在主布局中使用 alignParentTop=true 将其放在那里,并通过设置 android:layout_below="@+id/navBarLayout" 将 ListView 放在其下方

    【讨论】:

      猜你喜欢
      • 2019-08-23
      • 2011-03-06
      • 2016-08-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多