如何在图像中心对齐TextView

时间:2016-07-16 13:33:11

标签: 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: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"/>

任何人都有想法请帮帮我 我编辑了我的问题,这是我的问题。

2 个答案:

答案 0 :(得分:3)

例如,您可以使用RelativeLayoutTextView置于ImageView之上:

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

答案 1 :(得分:1)

您可以使用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>
相关问题