开发者

having problems with the xml layout, multiple relative layouts are being created

I have an array string that is added to an abc.xml and textview id label

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

In my abc.xml file I have a relative layout to show the nav bar, just once.

<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>

and then

<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"
>

which fills the textview with the array list

But the problem i have is the nav bar shows at the top followed by the first item in my array list then the nav bar follows again, then the second item from 开发者_开发问答my array list then the nav bar, this happens till the end of array list. Also as if, the navbar is in a loop with my arraylist. Now when i take off the content of the relative layout( navbar) leaving the textview, it shows perfectly but ofcourse i want the nav bar there showing once, ontop.


You need to seperate this:

<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"
>

into a different xml file perhaps call it row.xml Then use that file with your adapter. If you want the nav bar at the top then put it there with alignParentTop=true in your main layout, and put the ListView below it by setting android:layout_below="@+id/navBarLayout"

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜