Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/185.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
android布局对齐父项右对齐其匹配父项_Android_Android Layout - Fatal编程技术网

android布局对齐父项右对齐其匹配父项

android布局对齐父项右对齐其匹配父项,android,android-layout,Android,Android Layout,这是我的xml代码 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" android:lay

这是我的xml代码

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="false"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
>





    <customfonts.RoundedImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ssz"
        android:id="@+id/profile" />






    <customfonts.MyTextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/circulo"
        android:text="2"
        android:gravity="center_vertical|center_horizontal"
        android:textSize="13dp"
        android:textColor="#fff"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="false"
        android:layout_alignParentRight="false"
        />




      </RelativeLayout>
textView上

结果是这样的


如何解决此问题并使右侧图像上的
textView
对齐

您不想将其与父图像对齐。父对象是相对对象。您希望将其与图像对齐。这应该做到:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:layout_centerVertical="true"
                android:orientation="horizontal">

    <customfonts.RoundedImageView
        android:id="@+id/profile"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ssz"/>

    <customfonts.MyTextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:background="@drawable/circulo"
        android:layout_alignRight="@+id/profile"
        android:gravity="center_vertical|center_horizontal"
        android:text="2"
        android:textColor="#fff"
        android:textSize="13dp"/>

</RelativeLayout>

您不希望将其与父级对齐。父对象是相对对象。您希望将其与图像对齐。这应该做到:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:layout_centerVertical="true"
                android:orientation="horizontal">

    <customfonts.RoundedImageView
        android:id="@+id/profile"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ssz"/>

    <customfonts.MyTextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:background="@drawable/circulo"
        android:layout_alignRight="@+id/profile"
        android:gravity="center_vertical|center_horizontal"
        android:text="2"
        android:textColor="#fff"
        android:textSize="13dp"/>

</RelativeLayout>

将其更改为以下内容:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="false"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
>

    <customfonts.RoundedImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ssz"
        android:id="@+id/profile" />
    <customfonts.MyTextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/circulo"
        android:text="2"
        android:gravity="center_vertical|center_horizontal"
        android:textSize="13dp"
        android:textColor="#fff"
        android:layout_toRightOf="@id/profile"
        />

      </RelativeLayout>

将其更改为以下内容:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="false"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
>

    <customfonts.RoundedImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ssz"
        android:id="@+id/profile" />
    <customfonts.MyTextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/circulo"
        android:text="2"
        android:gravity="center_vertical|center_horizontal"
        android:textSize="13dp"
        android:textColor="#fff"
        android:layout_toRightOf="@id/profile"
        />

      </RelativeLayout>


当前文本视图的父级是相对布局。如果您希望文本视图位于图像视图的右侧,则文本视图的父视图应为图像视图或其父视图为相对布局的其他视图。您必须在Imageview中嵌套textview,或者您可以在另一个视图中嵌套Imageview,然后在该视图中嵌套textview。

当前文本视图的父视图是相对布局。如果您希望文本视图位于图像视图的右侧,则文本视图的父视图应为图像视图或其父视图为相对布局的其他视图。您必须将textview嵌套在Imageview中,或者您可以将Imageview嵌套在另一个视图中,然后将textview嵌套在该视图中。

我看不到代码上的左对齐或右对齐现在如何使其左对齐?它有
android:layout\u alignRight=“@+id/profile”
只需将其更改为
android:layout\u alignLeft=“@+id/profile”
您需要删除它,然后使用不同的布局参数重新添加它。我现在看不到代码上的左对齐或右对齐。如何使它左对齐?它有
android:layout\u alignRight=“@+id/profile”
只需将其更改为
android:layou alignLeft=“@+id/profile”
您需要删除它,然后使用不同的布局参数重新添加它