Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/195.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 如何在图像中心对齐TextView_Android_Android Linearlayout - Fatal编程技术网

Android 如何在图像中心对齐TextView

Android 如何在图像中心对齐TextView,android,android-linearlayout,Android,Android Linearlayout,我试图在图像中心显示文本视图,但无法在LinearLayout中工作。 <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <ImageView android:id="@+id/kurtis" android:layout_width="0dp" android:

我试图在图像中心显示文本视图,但无法在LinearLayout中工作。

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<ImageView
    android:id="@+id/kurtis"
    android:layout_width="0dp"
    android:layout_height="325dp"
    android:layout_weight="0.5"
    android:scaleType="fitXY"
    android:src="@mipmap/kurtis" />
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_text="Testing" />

<ImageView
    android:id="@+id/salwars"
    android:layout_width="0dp"
    android:layout_height="325dp"
    android:layout_marginLeft="10dp"
    android:layout_weight="0.5"
    android:scaleType="fitXY"
    android:src="@mipmap/salwar" />
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_text="Testing"/>

任何人有想法请帮助我。

我编辑了我的问题,这是我的问题。

例如,您可以使用
RelativeLayout
文本视图
集中在
图像视图
上:

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

    <RelativeLayout
        android:layout_width="0dp"
        android:layout_height="325dp"
        android:layout_weight="0.5">

        <ImageView
            android:id="@+id/kurtis"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scaleType="fitXY"
            android:src="@mipmap/salwar"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_text="Testing"/>
    </RelativeLayout>

    <RelativeLayout
        android:layout_width="0dp"
        android:layout_height="325dp"
        android:layout_weight="0.5">

        <ImageView
            android:id="@+id/salwars"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scaleType="fitXY"
            android:src="@mipmap/salwar"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_text="Testing"/>
    </RelativeLayout>
</LinearLayout>

例如,您可以使用
RelativeLayout
文本视图
置于
图像视图
的中心:

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

    <RelativeLayout
        android:layout_width="0dp"
        android:layout_height="325dp"
        android:layout_weight="0.5">

        <ImageView
            android:id="@+id/kurtis"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scaleType="fitXY"
            android:src="@mipmap/salwar"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_text="Testing"/>
    </RelativeLayout>

    <RelativeLayout
        android:layout_width="0dp"
        android:layout_height="325dp"
        android:layout_weight="0.5">

        <ImageView
            android:id="@+id/salwars"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scaleType="fitXY"
            android:src="@mipmap/salwar"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_text="Testing"/>
    </RelativeLayout>
</LinearLayout>

您可以使用FrameLayout进行此操作。它以所有的孩子为中心,比如:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:baselineAligned="false"
    android:orientation="horizontal">

    <FrameLayout
        android:layout_width="0dp"
        android:layout_height="325dp"
        android:layout_marginRight="10dp"
        android:layout_weight="1">

        <ImageView
            android:id="@+id/kurtis"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginTop="10dp"
            android:scaleType="fitXY"
            android:src="@mipmap/kurtis" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:text="Testing"
            android:textSize="18sp" />

    </FrameLayout>

    <FrameLayout
        android:layout_width="0dp"
        android:layout_height="325dp"
        android:layout_weight="1">

        <ImageView
            android:id="@+id/salwar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginTop="10dp"
            android:scaleType="fitXY"
            android:src="@mipmap/salwar" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:text="Testing"
            android:textSize="18sp" />

    </FrameLayout>

</LinearLayout>

您可以使用FrameLayout进行此操作。它以所有的孩子为中心,比如:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:baselineAligned="false"
    android:orientation="horizontal">

    <FrameLayout
        android:layout_width="0dp"
        android:layout_height="325dp"
        android:layout_marginRight="10dp"
        android:layout_weight="1">

        <ImageView
            android:id="@+id/kurtis"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginTop="10dp"
            android:scaleType="fitXY"
            android:src="@mipmap/kurtis" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:text="Testing"
            android:textSize="18sp" />

    </FrameLayout>

    <FrameLayout
        android:layout_width="0dp"
        android:layout_height="325dp"
        android:layout_weight="1">

        <ImageView
            android:id="@+id/salwar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginTop="10dp"
            android:scaleType="fitXY"
            android:src="@mipmap/salwar" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:text="Testing"
            android:textSize="18sp" />

    </FrameLayout>

</LinearLayout>


我建议您先使用相对布局,然后在布局\u中心对齐。我建议您先使用相对布局,然后在布局\u中心对齐。谢谢您的重播,欢迎您重播。此外,您应该将图像放入可绘制文件夹,而不是mipmap。Mipmap是专门为启动器图标设计的。不客气。此外,您应该将图像放入可绘制文件夹,而不是mipmap。Mipmap专门用于启动器图标。