如何对齐(一个的ImageView和一个TextView)的左侧和(一个ImageView的和一个TextView)至
问题描述:
我有具有两个ImageViews如何对齐(一个的ImageView和一个TextView)的左侧和(一个ImageView的和一个TextView)至
一个是左对齐并且一个是对准的标题栏的权利向右,像下面
<RelativeLayout
android:id="@+id/headersection"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:background="#181b1c" >
<ImageView
android:id="@+id/img_play"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_margin="5dp"
android:layout_marginRight="10dp"
android:contentDescription="@string/img_des"
android:src="@drawable/play" />
<ImageView
android:id="@+id/img_backicon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerHorizontal="true"
android:layout_margin="5dp"
android:layout_marginLeft="10dp"
android:contentDescription="@string/img_des"
android:src="@drawable/back" />
</RelativeLayout>
我想提出一个TextView每个图像旁,左侧的ImageView将有它旁边一个TextView(左对齐旁边左侧的ImageView)和右ImageView的将有一个在它旁边的TextView(对齐右侧ImageView旁边的右侧)...
我已经尝试了约30种不同的编码方式,不能弄明白
这里是什么,我试图做
<RelativeLayout
android:id="@+id/headersection"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:background="#181b1c" >
<!-- NEED TO PUT A TEXTVIEW HERE THAT ALIGNS TO THE RIGHT IMAGE BELOW -->
<TextView
android:id="@+id/RIGHT_TEXT"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="RIGHT TEXT HERE"
android:textColor="@color/Category_Title_Color"
android:textSize="20sp" />
<ImageView
android:id="@+id/img_play"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_margin="5dp"
android:layout_marginRight="10dp"
android:contentDescription="@string/img_des"
android:src="@drawable/play" />
<!-- NEED TO PUT A TEXTVIEW HERE THAT ALIGNS TO THE LEFT IMAGE BELOW -->
<TextView
android:id="@+id/LEFT_TEXT"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="LEFT TEXT HERE"
android:textColor="@color/Category_Title_Color"
android:textSize="20sp" />
<ImageView
android:id="@+id/img_backicon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerHorizontal="true"
android:layout_margin="5dp"
android:layout_marginLeft="10dp"
android:contentDescription="@string/img_des"
android:src="@drawable/back" />
</RelativeLayout>
当我试图做一个例子,文字不停重叠图像或不正确对齐。
任何帮助,将不胜感激
**** ****更新从 的cricket_007答案似乎为我工作得很好......这里是最终的代码,如果有人需要看它
<RelativeLayout
android:id="@+id/headersection"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:background="@color/colorbuttonbar" >
<TextView
android:id="@+id/img_play"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:gravity="center_vertical"
android:layout_margin="5dp"
android:layout_marginRight="10dp"
android:text="MUSIC - "
android:textStyle="bold"
android:textColor="@color/Notification_Bar_Title_Color"
android:drawableRight="@drawable/play" />
<TextView
android:id="@+id/img_backicon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerHorizontal="true"
android:gravity="center_vertical"
android:layout_margin="5dp"
android:layout_marginLeft="10dp"
android:text=" - GO BACK"
android:textStyle="bold"
android:textColor="@color/Notification_Bar_Title_Color"
android:drawableLeft="@drawable/back" />
</RelativeLayout>
答
您可能完全不需要ImageView
。
TextView
有左,右图像的两个属性:
例如,
<TextView
android:id="@+id/img_play"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_marginRight="10dp"
android:text="MUSIC - "
android:drawableRight="@drawable/play" /> <!-- See here -->
答
您是否尝试过使用android:layout_toRightOf
和android:layout_toLeftOf
以及android:layout_toStartOf
和android:layout_toEndOf
:
<RelativeLayout
android:id="@+id/headersection"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:background="#181b1c">
<TextView
android:text="TextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="@+id/textView" />
<TextView
android:text="TextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:id="@+id/textView2" />
<ImageView
android:id="@+id/img_backicon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/back"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/textView"
android:layout_toEndOf="@+id/textView" />
<ImageView
android:id="@+id/img_play"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/play"
android:layout_alignParentTop="true"
android:layout_toLeftOf="@+id/textView2"
android:layout_toStartOf="@+id/textView2" />
</RelativeLayout>
哇靠.....你是认真的LOL 所以我会对准TextView的向左和向右,只是使用附加的图像,每个的TextView属性android:drawableLeft和android:drawableRight取决于textview? – skapaid
继续尝试吧:) –
这对我有用,我将在更新后的问题中包含完成代码 – skapaid