![](/img/trans.png)
[英]How to place 2 items at right using android:layout_toRightOf
[英]Why I can't place view with layout_toRightOf the right of view with layout_alignParentRight=“true”
我想將一個TextView
與一個layout_alignParentRight="true"
的ImageView
layout_toRightOf
放置。 為什么我看不到TextView
? 如何解決這個問題。
我的問題代碼!
<RelativeLayout
android:orientation="horizontal"
android:minWidth="20px"
android:minHeight="20px"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/bottomBar">
<ImageButton
android:src="@drawable/likes"
android:background="#ffffff"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_marginRight="8dp"
android:id="@+id/likeImage"
android:layout_alignParentLeft="true"
android:layout_marginLeft="15dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/likeImage"
android:id="@+id/likeText" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="@+id/tv_progress">
<ImageButton
android:src="@drawable/coment"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_marginRight="4dp"
android:id="@+id/comment" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:id="@+id/commentText" />
</LinearLayout>
<ImageButton
android:id="@+id/repostImage"
android:background="#ffffff"
android:src="@drawable/repost"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_alignParentRight="true"
android:layout_marginRight="45dp" />
<TextView
android:layout_toRightOf="@+id/repostImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="77"
android:id="@+id/repostText" />
</RelativeLayout>
為什么我看不到文字“ 77”?
解決了該問題,但ImageView
尚未修復。 由於固定的TextView
<ImageButton
android:id="@+id/repostImage"
android:layout_toLeftOf="@+id/repostText"
android:background="#ffffff"
android:src="@drawable/repost"
android:layout_width="25dp"
android:layout_height="25dp" />
<TextView
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/repostText"
android:layout_marginLeft="10dp"
android:layout_marginRight="15dp" />
我的解決方案只需使用android:layout_alignParentRight="true"
在LinearLayout
包裝右鍵和android:layout_alignParentRight="true"
使用此代碼
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center"
android:layout_alignParentRight="true"
>
<ImageButton
android:id="@+id/repostImage"
android:background="#ffffff"
android:src="@drawable/repost"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_alignParentRight="true"
android:layout_marginRight="45dp" />
<TextView
android:layout_toRightOf="@+id/repostImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="77"
android:id="@+id/repostText"
android:layout_marginLeft="15dp" />
</LinearLayout>
</RelativeLayout>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.