简体   繁体   中英

Why I can't place view with layout_toRightOf the right of view with layout_alignParentRight=“true”

I want to place a TextView with layout_toRightOf of an ImageView with layout_alignParentRight="true" . Why I cannot see TextView ? How to solve this.

My problem code!

<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>

Why I cannot see text "77"?

Worked the solution but the ImageView is not fixed yet. Because of the fixed 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" />

Here's the screen added with the problem: 在此处输入图片说明

My solution Just wrap right button andt textview in LinearLayout with android:layout_alignParentRight="true"

use this code

<?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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM