我一直在研究一個簡單的UI,其中顯示一些照片和其他信息! 我有一個簡單的佈局來顯示每個照片在一個盒子裏,我想多次添加這個佈局dinamicaly(我有照片的數量)。使用LayoutInflater將相同視圖多次添加到彼此的下方
這是我info_wrapper.xml文件
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/info_wrapper"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="2dp"
android:paddingBottom="2dp"
android:paddingLeft="1dp"
android:paddingRight="1dp"
>
<TextView
android:id="@+id/usernamePosting"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello"/>
<ImageView
android:below="@+id/usernamePosting"
android:id="@+id/photo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello"/>
</RelativeLayout>
而且我main_screen.xml文件:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="match_parent" >
<RelativeLayout
android:id="@+id/menuBar"
android:layout_width="fill_parent"
android:layout_height="20dp"
android:background="@color/green">
<ImageView
android:id="@+id/locationIcon"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:src="@drawable/location_place"
></ImageView>
<TextView
android:id="@+id/userLocationTxtView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_toRightOf="@+id/locationIcon"
android:text="@string/app_name"
android:textColor="@color/white"
android:textSize="15dp" />
</RelativeLayout>
<RelativeLayout
android:layout_below="@id/menuBar"
android:id="@+id/bodyView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/light_gray">
</RelativeLayout>
</RelativeLayout>
現在,當我嘗試添加多次info_wrapper視圖 - 對所有視圖AR彼此頂部 - 但我想成爲一個低於其他
什麼是它應該是什麼樣子的?考慮使用'LinearLayout'(或'ListView'和'ListAdapter') – Tedil 2013-03-04 20:19:14
它看起來像一個listview - 但在列表視圖中的一些行之間,我有時必須添加其他信息...所以我不認爲我可以使用!像這樣的東西 - http://stackoverflow.com/questions/13955122/android-foursquare-display – Alin 2013-03-04 20:26:09
以及你*可以*使用一個自定義適配器的列表視圖,膨脹不同類型的數據項不同的佈局 – Tedil 2013-03-04 20:37:01