出于某种原因,android:layout_height="200sp"
属性没有任何效果。预览会在Android Studio中正确绘制,但如果我运行我的应用程序,则列表项不会根据android:layout_height="200sp"
更改其大小。我正在使用此RelativeLayout
作为ListView
的列表项。的RelativeLayout:安卓:layout_height没有效果
有什么建议吗?
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="120dip"
android:background="#ffffff"
>
<ImageView
android:id="@+id/icon"
android:src="@drawable/ic_launcher"
android:layout_width="50dip"
android:layout_height="50dip"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
android:layout_gravity="center"
/>
</RelativeLayout>
@Edit:
我做了一个简单的例子。我认为列表中的项目高度为120dip
,左侧的图标尺寸为50x50 dip
。实际情况是,出于某种原因,列表项目与ImageView
具有相同的高度。
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
ViewHolder holder;
if(convertView == null){
convertView = mInflater.inflate(R.layout.listview_nearbylist_item, null);
holder = new ViewHolder();
//holder.text1 = (TextView) convertView.findViewById(R.id.text1);
//holder.text2 = (TextView) convertView.findViewById(R.id.text2);
//holder.text3 = (TextView) convertView.findViewById(R.id.text3);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
//holder.text1.setText(items.get(position).getRestaurantName());
//holder.text2.setText(items.get(position).getRestaurantGenre());
//holder.text3.setText("08:00 - 18:00 Uhr");
return convertView;
}
快速提示:您应该使用'dp'而不是'sp'来布局布局,除非您特别擅长副作用,否则会导致某些用户配置。 –
@MarcinOrlowski谢谢你的提示!只是有这么多的单位..:d – displayname
“列表中的项目并没有改变它们的大小” - 这意味着你正在使用这个'RelativeLayout'在一个'ListView'或'RecyclerView'行。如果是这样,请将代码放在膨胀布局的位置。 – CommonsWare