简体   繁体   中英

Android layout issue with sibling of RelativeLayout

I add add LinearLayout with horizontal orientation to my Android layout, but unfortunately there is an error: id/title_dialog_text_view is not a sibling in the same RelativeLayout.

I am trying to combine TextView and ProgressBar in horizontal not vertical line.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_below="@+id/title_dialog_text_view"
        android:layout_marginTop="6dp"
        android:layout_marginLeft="6dp"
        android:layout_marginRight="6dp"
        android:paddingBottom="20dp"
        android:gravity="center_horizontal"
        android:orientation="vertical">
        <TextView
            android:id="@+id/title_dialog_text_view"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="10dp"
            android:text=""
            android:textSize="18sp"/>
        <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <ProgressBar
          android:id="@+id/pb_loading"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          style="@android:style/Widget.ProgressBar.Small"/>
        <TextView
            android:id="@+id/text_dialog_text_view"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_centerInParent="true"
            android:gravity="center"
            android:layout_margin="20dp"
            android:lineSpacingExtra="6dp"
            android:text=""
            android:textSize="16sp"/>
    </LinearLayout>
    </LinearLayout>
</RelativeLayout>

this error is because parent of TextView and LinearLayout are not same. if you want to put TextView and ProgressBar horizontal , change their parent's orientation to horizontal

May this solves your problem :

<ProgressBar
    android:id="@+id/pb_loading"
    style="@android:style/Widget.ProgressBar.Small"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="20dp" />

<TextView
    android:id="@+id/text_dialog_text_view"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="20dp"
    android:gravity="center"
    android:text=""
    android:textSize="16sp" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM