相对布局
问题描述:
我不很了解的RelativeLayout,我不明白为什么这个XML(它代表了一个列表视图的项目):相对布局
<?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/sfumatura_riga"
>
<ImageView
android:id="@+id/featured_new_image"
android:layout_alignParentLeft="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/no_foto"
/>
<LinearLayout
android:layout_toRightOf="@id/featured_new_image"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
>
<TextView
style="@style/featured_new_title"
android:id="@+id/featured_city"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginTop="10dp"
/>
<TextView
style="@style/featured_name_country"
android:id="@+id/featured_country"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
<TextView
style="@style/featured_date"
android:id="@+id/featured_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginRight="5dp"
android:layout_alignParentRight="true"
/>
</RelativeLayout>
我遇见这样的结果,为什么太多的余量该行的底部?
答
我将主要看两点:
- 在相对布局,改变
android:layout_height="fill_parent" to android:layout_height="wrap content"
- 我猜的背景只是一个梯度。但是,如果它是一个图像,那么它可能太大而整行被垂直拉伸。 !
答
感谢ATL所有我解决它与一个LinearLayout中更换RelativeLaoyout,我分享的解决方案,我希望能帮助别人谁具有相同的问题:
<ImageView
android:id="@+id/featured_new_image"
android:layout_width="120dp"
android:layout_height="fill_parent"
android:src="@drawable/no_foto"
/>
<LinearLayout
android:orientation="vertical"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
>
<TextView
style="@style/featured_new_title"
android:id="@+id/featured_city"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginTop="10dp"
/>
<TextView
style="@style/featured_name_country"
android:id="@+id/featured_country"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
<TextView
style="@style/featured_date"
android:id="@+id/featured_date"
android:layout_marginTop="10dp"
android:layout_marginRight="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
/>
如果您试图将相对布局的layout_height更改为wrap_content,它是否工作? – xandy 2011-01-12 10:38:25
我没有得到任何错误在这个XML。 – 2011-01-12 10:42:42