-1

I have this layout below. My goal is to keep the progress bar and the button below the TextView and the progressBar directly on the right of the button. What should I change?

enter image description here

   <LinearLayout
        android:id="@+id/linearLayout"
        android:layout_width="368dp"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:layout_alignParentTop="true"
        android:weightSum="1"
        tools:layout_editor_absoluteY="0dp"
        tools:layout_editor_absoluteX="8dp">

        <TextView
            android:id="@+id/myText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentEnd="true"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:text="hello guys"
            android:textAlignment="center"
            android:textAllCaps="false"
            android:textStyle="italic" />

        <ProgressBar
            android:id="@+id/myProgressBar"
            style="?android:attr/progressBarStyle"
            android:layout_width="wrap_content"
            android:layout_height="20dp"
            android:visibility="visible" />

        <Button
            android:id="@+id/buttonID"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:enabled="false"
            android:text="my button" />

    </LinearLayout>
Jonathan Doe
  • 101
  • 5
  • 20

2 Answers2

1

Use a RelativeLayout instead of a LinearLayout. With RelativeLayout you can use toRightOf

Please research more before you ask a basic question

Layout File - Positioning Item to Right of Another Item (Android)

MacLean Sochor
  • 435
  • 5
  • 14
  • but I want to keep the progress bar and the button below the TextView . don't I need a vertical linear layout for that? please post some code . thanks for answering – Jonathan Doe Jul 17 '17 at 19:06
  • RelativeLayouts also allow you to use `layout_below`. Again, please look at SO questions and documentation before you ask a question – MacLean Sochor Jul 17 '17 at 19:07
1

Put Button and ProgressBar inside RelativeLayout. Then move Button to center of RelativeLayout with layout_centerInParent="true" and finally set ProgressBar aligned to right of button with layout_toRightOf="@+id/buttonID"

<LinearLayout
    android:id="@+id/linearLayout"
    android:layout_width="368dp"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:orientation="vertical"
    android:weightSum="1"
    tools:layout_editor_absoluteX="8dp"
    tools:layout_editor_absoluteY="0dp">

    <TextView
        android:id="@+id/myText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentEnd="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:text="hello guys"
        android:textAlignment="center"
        android:textAllCaps="false"
        android:textStyle="italic" />

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

        <Button
            android:id="@+id/buttonID"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:enabled="false"
            android:text="my button" />

        <ProgressBar
            android:id="@+id/myProgressBar"
            style="?android:attr/progressBarStyle"
            android:layout_toRightOf="@+id/buttonID"
            android:layout_centerVertical="true"
            android:layout_width="20dp"
            android:layout_height="20dp"
            android:visibility="visible" />
    </RelativeLayout>

</LinearLayout>
SiSa
  • 2,594
  • 1
  • 15
  • 33