jhulst
jhulst

Reputation: 373

How to vertically align EditText and ProgressBar in horizontal LinearLayout?

In my layout I have four blocks like these:

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

    <EditText
        android:id="@+id/label1"
        android:layout_width="100dip"
        android:layout_height="wrap_content"
        android:clickable="false"
        android:focusable="false"
        android:focusableInTouchMode="false"
        android:text="@string/freq_1_50" />
    <ProgressBar android:id="@+id/progress_horizontal1"
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_width="100dip"
        android:layout_height="wrap_content"
        android:max="100"
        android:progress="50" />
    <EditText
        android:id="@+id/textScore1"
        android:layout_width="100dip"
        android:layout_height="wrap_content"
        android:focusable="false"
        android:focusableInTouchMode="false"
        android:inputType="none"
        android:text="50%" />

</LinearLayout>

Resulting in this picture in the android emulator:

enter image description here

The obvious questions is: how do I go about in vertically aligning the EditText and progressbar?

Thanks in advance!

Here is the desired result of adding the center attribute:

enter image description here

Problem solved!

Upvotes: 0

Views: 1632

Answers (2)

Tuna Karakasoglu
Tuna Karakasoglu

Reputation: 1267

Try

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

android:gravity = "center">

<EditText
    android:id="@+id/label1"
    android:layout_width="100dip"
    android:layout_height="wrap_content"
    android:clickable="false"
    android:focusable="false"
    android:focusableInTouchMode="false"
    android:text="@string/freq_1_50" />
<ProgressBar android:id="@+id/progress_horizontal1"
    style="?android:attr/progressBarStyleHorizontal"
    android:layout_width="100dip"
    android:layout_height="wrap_content"
    android:max="100"
    android:progress="50" />
<EditText
    android:id="@+id/textScore1"
    android:layout_width="100dip"
    android:layout_height="wrap_content"
    android:focusable="false"
    android:focusableInTouchMode="false"
    android:inputType="none"
    android:text="50%" />

Upvotes: 2

Manoj Kumar
Manoj Kumar

Reputation: 1521

Just add android:gravity = "center" to your Linear layout above

Upvotes: 0

Related Questions