如何在relativelayout android中同等设置imageview间距?
问题描述:
我的疑问是如何allign的imageview的并且TextView的的RelativeLayout的任何其它或布局我想里面同样间距但未能成功在它让我后我的代码是我迄今尝试:如何在relativelayout android中同等设置imageview间距?
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/swiperefresh"
tools:context=".Activities.VisitView"
android:background="#e3e3e3">
<RelativeLayout
android:layout_width="match_parent"
android:orientation="horizontal"
android:id="@+id/parent"
android:background="#e3e3e3"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:background="#fff"
android:layout_margin="20dp"
android:id="@+id/child"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="wrap_content"
android:id="@+id/first"
android:layout_height="wrap_content">
<de.hdodenhof.circleimageview.CircleImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:id="@+id/e"
android:layout_centerHorizontal="true"
android:src="@drawable/ic_downloads"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Download"
android:layout_marginTop="5dp"
android:layout_marginLeft="10dp"
android:layout_centerHorizontal="true"
android:textSize="12sp"
android:layout_below="@+id/e"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/first"
android:layout_marginLeft="10dp"
android:id="@+id/second">
<de.hdodenhof.circleimageview.CircleImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:id="@+id/e1"
android:layout_centerHorizontal="true"
android:src="@drawable/ic_up_arrow"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Upload"
android:layout_centerHorizontal="true"
android:layout_marginTop="5dp"
android:textSize="12sp"
android:layout_marginLeft="10dp"
android:layout_below="@+id/e1"/>
</RelativeLayout>
<RelativeLayout
android:layout_marginLeft="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/second"
android:id="@+id/third">
<de.hdodenhof.circleimageview.CircleImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:id="@+id/e3"
android:layout_centerHorizontal="true"
android:src="@drawable/ic_up_arrow"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Print"
android:layout_centerHorizontal="true"
android:layout_marginTop="5dp"
android:textSize="12sp"
android:layout_marginLeft="10dp"
android:layout_below="@+id/e3"/>
</RelativeLayout>
<RelativeLayout
android:layout_marginLeft="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/third"
android:id="@+id/four">
<de.hdodenhof.circleimageview.CircleImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:id="@+id/e4"
android:layout_centerHorizontal="true"
android:src="@drawable/ic_up_arrow"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Notes"
android:layout_centerHorizontal="true"
android:layout_marginTop="5dp"
android:textSize="12sp"
android:layout_marginLeft="10dp"
android:layout_below="@+id/e4"/>
</RelativeLayout>
</RelativeLayout>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/child"
android:layout_marginTop="5dp"
android:id="@+id/visit"
android:layout_marginBottom="5dp"
android:divider="#e3e3e3"
android:keepScreenOn="true"
android:scrollbars="vertical"
android:dividerHeight="0.5dp"
/>
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
但textview和imageview没有正确地在相对布局内部进行匹配,这是图像
如何正确地对齐此图像和textview预先感谢!
答
试试这个,
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/swiperefresh"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#e3e3e3">
<RelativeLayout
android:id="@+id/parent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#e3e3e3"
android:orientation="horizontal">
<LinearLayout
android:id="@+id/child"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:background="#fff"
android:orientation="horizontal">
<RelativeLayout
android:id="@+id/first"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/e"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:src="@drawable/ic_up_arrow" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/e"
android:layout_centerHorizontal="true"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:text="Download"
android:textSize="12sp" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/second"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_weight="1">
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/e1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:src="@drawable/ic_up_arrow" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/e1"
android:layout_centerHorizontal="true"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:text="Upload"
android:textSize="12sp" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/third"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_weight="1">
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/e3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:src="@drawable/ic_up_arrow" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/e3"
android:layout_centerHorizontal="true"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:text="Print"
android:textSize="12sp" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/four"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_weight="1">
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/e4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:src="@drawable/ic_up_arrow" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/e4"
android:layout_centerHorizontal="true"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:text="Notes"
android:textSize="12sp" />
</RelativeLayout>
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/visit"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/child"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:divider="#e3e3e3"
android:dividerHeight="0.5dp"
android:keepScreenOn="true"
android:scrollbars="vertical" />
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
答
试试这个
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/swiperefresh"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#e3e3e3"
tools:context=".Activities.VisitView">
<RelativeLayout
android:id="@+id/parent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#e3e3e3"
android:orientation="horizontal">
<LinearLayout
android:id="@+id/child"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:background="#fff"
android:orientation="horizontal">
<RelativeLayout
android:id="@+id/first"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1">
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/e"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:src="@drawable/ic_downloads" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/e"
android:layout_centerHorizontal="true"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:text="Download"
android:textSize="12sp" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/second"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_toRightOf="@+id/first"
android:layout_weight="1">
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/e1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:src="@drawable/ic_up_arrow" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/e1"
android:layout_centerHorizontal="true"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:text="Upload"
android:textSize="12sp" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/third"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_toRightOf="@+id/second"
android:layout_weight="1">
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/e3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:src="@drawable/ic_up_arrow" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/e3"
android:layout_centerHorizontal="true"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:text="Print"
android:textSize="12sp" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/four"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_toRightOf="@+id/third"
android:layout_weight="1">
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/e4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:src="@drawable/ic_up_arrow" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/e4"
android:layout_centerHorizontal="true"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:text="Notes"
android:textSize="12sp" />
</RelativeLayout>
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/visit"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/child"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:divider="#e3e3e3"
android:dividerHeight="0.5dp"
android:keepScreenOn="true"
android:scrollbars="vertical" />
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
答
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/swiperefresh"
android:background="#e3e3e3">
<RelativeLayout
android:layout_width="match_parent"
android:orientation="horizontal"
android:id="@+id/parent"
android:background="#e3e3e3"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:background="#fff"
android:layout_margin="20dp"
android:orientation="horizontal"
android:id="@+id/child"
android:layout_height="wrap_content">
<RelativeLayout
android:id="@+id/first"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
<de.hdodenhof.circleimageview.CircleImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:id="@+id/e"
android:layout_centerHorizontal="true"
android:src="@drawable/inactive_settings"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Download"
android:layout_marginTop="5dp"
android:layout_marginLeft="10dp"
android:layout_centerHorizontal="true"
android:textSize="12sp"
android:layout_below="@+id/e"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_toRightOf="@+id/first"
android:layout_marginLeft="10dp"
android:id="@+id/second">
<de.hdodenhof.circleimageview.CircleImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:id="@+id/e1"
android:layout_centerHorizontal="true"
android:src="@drawable/inactive_settings"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Upload"
android:layout_centerHorizontal="true"
android:layout_marginTop="5dp"
android:textSize="12sp"
android:layout_marginLeft="10dp"
android:layout_below="@+id/e1"/>
</RelativeLayout>
<RelativeLayout
android:layout_marginLeft="10dp"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_toRightOf="@+id/second"
android:id="@+id/third">
<de.hdodenhof.circleimageview.CircleImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:id="@+id/e3"
android:layout_centerHorizontal="true"
android:src="@drawable/inactive_settings"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Print"
android:layout_centerHorizontal="true"
android:layout_marginTop="5dp"
android:textSize="12sp"
android:layout_marginLeft="10dp"
android:layout_below="@+id/e3"/>
</RelativeLayout>
<RelativeLayout
android:layout_marginLeft="10dp"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_toRightOf="@+id/third"
android:id="@+id/four">
<de.hdodenhof.circleimageview.CircleImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:id="@+id/e4"
android:layout_centerHorizontal="true"
android:src="@drawable/inactive_settings"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Notes"
android:layout_centerHorizontal="true"
android:layout_marginTop="5dp"
android:textSize="12sp"
android:layout_marginLeft="10dp"
android:layout_below="@+id/e4"/>
</RelativeLayout>
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/child"
android:layout_marginTop="5dp"
android:id="@+id/visit"
android:layout_marginBottom="5dp"
android:divider="#e3e3e3"
android:keepScreenOn="true"
android:scrollbars="vertical"
android:dividerHeight="0.5dp"
/>
</RelativeLayout>
答
使用的LinearLayout与重量之和:
<RelativeLayout
android:layout_width="match_parent"
android:orientation="horizontal"
android:id="@+id/parent"
android:background="#e3e3e3"
android:layout_height="match_parent">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:background="#fff"
android:layout_margin="20dp"
android:id="@+id/child"
android:weightSum="4"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_weight="1"
android:layout_width="wrap_content"
android:id="@+id/first"
android:layout_height="wrap_content">
<de.hdodenhof.circleimageview.CircleImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:id="@+id/e"
android:layout_centerHorizontal="true"
android:src="@drawable/ic_downloads"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Download"
android:layout_marginTop="5dp"
android:layout_marginLeft="10dp"
android:layout_centerHorizontal="true"
android:textSize="12sp"
android:layout_below="@+id/e"/>
</RelativeLayout>
<RelativeLayout
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/first"
android:layout_marginLeft="10dp"
android:id="@+id/second">
<de.hdodenhof.circleimageview.CircleImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:id="@+id/e1"
android:layout_centerHorizontal="true"
android:src="@drawable/ic_up_arrow"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Upload"
android:layout_centerHorizontal="true"
android:layout_marginTop="5dp"
android:textSize="12sp"
android:layout_marginLeft="10dp"
android:layout_below="@+id/e1"/>
</RelativeLayout>
<RelativeLayout
android:layout_weight="1"
android:layout_marginLeft="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/second"
android:id="@+id/third">
<de.hdodenhof.circleimageview.CircleImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:id="@+id/e3"
android:layout_centerHorizontal="true"
android:src="@drawable/ic_up_arrow"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Print"
android:layout_centerHorizontal="true"
android:layout_marginTop="5dp"
android:textSize="12sp"
android:layout_marginLeft="10dp"
android:layout_below="@+id/e3"/>
</RelativeLayout>
<RelativeLayout
android:layout_weight="1"
android:layout_marginLeft="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/third"
android:id="@+id/four">
<de.hdodenhof.circleimageview.CircleImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:id="@+id/e4"
android:layout_centerHorizontal="true"
android:src="@drawable/ic_up_arrow"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Notes"
android:layout_centerHorizontal="true"
android:layout_marginTop="5dp"
android:textSize="12sp"
android:layout_marginLeft="10dp"
android:layout_below="@+id/e4"/>
</RelativeLayout>
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/child"
android:layout_marginTop="5dp"
android:id="@+id/visit"
android:layout_marginBottom="5dp"
android:divider="#e3e3e3"
android:keepScreenOn="true"
android:scrollbars="vertical"
android:dividerHeight="0.5dp"
/>
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
答
请参考这一点,实现相对layout.Place内的线性布局到位相对布局我的图像视图的图像视图。
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/relativeLayout2"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp">
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
app:srcCompat="@drawable/tv"
android:id="@+id/starImage" />
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
app:srcCompat="@drawable/music"
android:id="@+id/callImage" />
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
app:srcCompat="@drawable/books"
android:id="@+id/shareImage" />
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
app:srcCompat="@drawable/block_icon"
android:id="@+id/blockImage" />
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
app:srcCompat="@drawable/edit"
android:id="@+id/deleteimage" />
</LinearLayout>
输出将lokk这样。
尝试使用'LinearLayout'用'weight' –
你不能这样做,因为你的文字是不同的。为此,必须设置Relativelayout –
yes @PhanVanLinh右侧的固定高度宽度。您还可以使用带有weightSum的Main LinearLayout和带有权重的Inner LinearLayout –