[英]relative layout margin not working?
I am trying to set the margin to the relative layout, but its not working, wondering why? 我正在尝试将边距设置为相对布局,但无法正常工作,想知道为什么吗?
here is the layout containing listview, 这是包含listview的布局,
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:paddingTop="10dip">
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scrollbarStyle="outsideOverlay"/>
and here is the view i want to inflate in that list view, 这是我要在该列表视图中添加的视图,
<?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="wrap_content"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"
android:background="@drawable/subcat_list_selector" >
<ImageView
android:id="@+id/categoryIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<!-- Rightend Arrow -->
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="5dp"
android:src="@drawable/right_nav" />
<TextView
android:id="@+id/categoryTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:layout_toRightOf="@+id/categoryIcon"
android:gravity="center_vertical"
android:text="@string/my_string"
android:textColor="#999999"
android:textSize="15sp" />
Give a child relative layout inside the main layout with margin 在主布局内给孩子一个相对布局
<?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="wrap_content"
android:background="@drawable/subcat_list_selector" >
<RelativeLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp">
<ImageView
android:id="@+id/categoryIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<!-- Rightend Arrow -->
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="5dp"
android:src="@drawable/right_nav" />
<TextView
android:id="@+id/categoryTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:layout_toRightOf="@+id/categoryIcon"
android:gravity="center_vertical"
android:text="@string/my_string"
android:textColor="#999999"
android:textSize="15sp" />
</RelativeLayout>
</RelativeLayout>
But this gives you a warning that the child layout is useless. 但这会警告您子布局无效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.