簡體   English   中英

如何在Android中的RelativeLayout中的TextView下對齊視圖

[英]How to align a View below a TextView in a RelativeLayout in Android

試圖在RelativeLayout中的TextView下方放置一個View
下面的代碼不起作用。

請幫忙。

<RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >

    <TextView
        android:id="@+id/tv_Following"
        android:layout_width="60dp"
        android:layout_height="60dp"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:background="@drawable/circulartextview"
        android:gravity="center"
        android:text="Followings"
        android:textColor="@color/white"
        android:textSize="10dp" />

    <View
        android:id="@+id/flg1"
        android:layout_width="4dp"
        android:layout_height="wrap_content"
        android:layout_below="@id/tv_Following"
        android:layout_centerHorizontal="true"
        android:background="@color/grey2" />

</RelativeLayout>

在此處輸入圖片說明

您只需要在TextView中使用android:layout_centerInParent="true"
所以要讀

        <TextView
            android:id="@+id/tv_Following"
            android:layout_width="60dp"
            android:layout_height="60dp"
            android:layout_centerInParent="true"
            android:background="@drawable/circulartextview"
            android:gravity="center"
            android:text="Followings"
            android:textColor="@color/white"
            android:textSize="10dp" />

AND從@id引用中刪除多余的+
所以要讀

        <View
            android:id="@+id/flg1"
            android:layout_width="4dp"
            android:layout_height="wrap_content"
            android:layout_below="@id/tv_Following"
            android:layout_centerHorizontal="true"
            android:layout_alignParentBottom="true"
            android:background="@color/grey2" />

否則,您將創建名稱為tv_Following新ID。
而且它不能引用正確的。

還要注意我改變了這個

android:layout_alignParentBottom="@+id/tv_Following"

android:layout_alignParentBottom="true"

替換為

<View
    android:id="@+id/flg1"
    android:layout_width="4dp"
    android:layout_height="match_parent"
    android:layout_below="@id/tv_Following"
    android:layout_centerHorizontal="true"
    android:layout_alignParentBottom="true"
    android:background="@color/grey2" />

並為您的相對布局父級或flg1視圖定義尺寸。 例如

<RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="82dp">

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM