Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/200.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 - Fatal编程技术网

Android 水平居中文本视图内部图像视图

Android 水平居中文本视图内部图像视图,android,Android,如何在ImageView内水平居中放置TextView? 当前位于ImageView的右下角 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" a

如何在ImageView内水平居中放置TextView? 当前位于ImageView的右下角

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/imageView"
        android:background="@drawable/img" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/textView"
        android:layout_alignBottom="@+id/imageView"
        android:layout_alignRight="@+id/imageView"
        android:layout_alignEnd="@+id/imageView" />
</RelativeLayout>
尝试FrameLayout而不是RelativeLayout,并将重心设置为中心

尝试FrameLayout而不是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">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/imageView"
        android:background="@drawable/img" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/textView"
        android:text="hsjsdjhf"
        android:layout_centerInParent="true" />
</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">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/imageView"
        android:background="@drawable/img" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/textView"
        android:text="hsjsdjhf"
        android:layout_centerInParent="true" />
</RelativeLayout>
如果您希望TextView始终独立地与ImageView大小相匹配(位于RelativeLayout上),则应尝试以下操作:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/imageView"
        android:background="@drawable/img" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/textView"
        android:text="hsjsdjhf"
        android:gravity="center"
        android:layout_alignTop="@id/imageView"
        android:layout_alignBottom="@id/imageView"
        android:layout_alignLeft="@id/imageView"
        android:layout_alignRight="@id/imageView" />
</RelativeLayout>
如果您希望TextView始终独立地与ImageView大小相匹配(位于RelativeLayout上),则应尝试以下操作:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/imageView"
        android:background="@drawable/img" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/textView"
        android:text="hsjsdjhf"
        android:gravity="center"
        android:layout_alignTop="@id/imageView"
        android:layout_alignBottom="@id/imageView"
        android:layout_alignLeft="@id/imageView"
        android:layout_alignRight="@id/imageView" />
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/imageView"
            android:background="@drawable/texts" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/textView"
        android:text="hello world"
        android:layout_centerInParent="true"/>
    </RelativeLayout>

</RelativeLayout>