ska*_*aid 0 android android-layout android-fragments
我有一个标题栏,它有两个 ImageViews
一个左对齐,一个右对齐,如下图
<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>
Run Code Online (Sandbox Code Playgroud)
我想在每个图像旁边放一个 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>
Run Code Online (Sandbox Code Playgroud)
当我尝试这样做时,文本一直与图像重叠或未正确对齐。
任何帮助,将不胜感激
****更新**** 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>
Run Code Online (Sandbox Code Playgroud)
你可能根本不需要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 -->
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
596 次 |
| 最近记录: |