Android 解决包含布局冲突
因此,我有3种布局,如下所示:Android 解决包含布局冲突,android,xml,Android,Xml,因此,我有3种布局,如下所示: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/list" android:layout_width="match_parent" android:layout_height="match_parent" >
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<include layout="@layout/first" />
<include layout="@layout/second" />
<include layout="@layout/third" />
</LinearLayout>
String[] values = {"outlet_name","reward","locality","distance"};
int[] ids = {R.id.outlet_name,R.id.reward,R.id.locality,R.id.distance};
adapter = new SimpleAdapter(getActivity(), oslist,
R.layout.all, values,ids);
list.setAdapter(adapter);
((SimpleAdapter) adapter).notifyDataSetChanged();
first.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/reward_icon"
android:layout_marginLeft="15dp"
android:layout_height="55dp"
android:layout_width="55dp"
android:src="@drawable/gift"/>
<TextView
android:id="@+id/outlet_name"
android:layout_toRightOf="@id/reward_icon"
android:layout_marginRight="45dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft = "15dip"
android:hint="outlet"
/>
<TextView
android:id="@+id/distance"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:hint="0.0km"/>
<TextView
android:id="@+id/reward"
android:layout_toRightOf="@id/reward_icon"
android:layout_toLeftOf="@id/distance"
android:layout_below="@id/outlet_name"
android:layout_marginRight="15dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft = "15dip"
android:hint="Reward"
/>
<TextView
android:id="@+id/locality"
android:layout_toRightOf="@id/reward_icon"
android:layout_toLeftOf="@id/distance"
android:layout_below="@id/reward"
android:layout_marginRight="15dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft = "15dip"
android:hint="Locality"
/>
</RelativeLayout>
我如何解决这个问题?试试这种方法,希望这能帮助您解决问题。
1.Add this properties android:orientation="vertical" to your LinearLayout in all.xml
2.Change this properties android:layout_height="match_parent" to android:layout_height="wrap_content" RelativeLayout in first.xml,second.xml and third.xml.
我可以知道什么是
R.all
?参考all.xml布局。将这个android:orientation=“vertical”添加到all.xml线性布局,并将android:layout\u height=“wrap\u content”设置为第一、第二和第三个xml相对布局。@Haresh嘿,我在emulator上遇到一些问题,所以花了一些时间。对不起,它坏了。现在,对于每个数据,所有布局都显示一次。不,不是。现在它只显示了3次布局。一次带数据,两次不带数据。您可以发布oslist值吗?
String[] values = {"outlet_name","reward","locality","distance"};
int[] ids = {R.id.outlet_name,R.id.reward,R.id.locality,R.id.distance};
adapter = new SimpleAdapter(getActivity(), oslist,
R.layout.all, values,ids);
list.setAdapter(adapter);
((SimpleAdapter) adapter).notifyDataSetChanged();
1.Add this properties android:orientation="vertical" to your LinearLayout in all.xml
2.Change this properties android:layout_height="match_parent" to android:layout_height="wrap_content" RelativeLayout in first.xml,second.xml and third.xml.