0

В моем макете у меня есть четыре блока, как это:Как вертикально выравнивать EditText и ProgressBar в горизонтальном LinearLayout?

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

в результате чего в этой картине в эмуляторе Android:

enter image description here

Очевидный вопросы: как я могу идти о в вертикальном выравнивании EditText и progressbar?

Заранее благодарен!

Вот желаемый результат добавления атрибута центра:

enter image description here

Проблема решена!

+0

Мне любопытно, как вы это решили? – JJ86

ответ

2

Попробуйте

<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%" /> 

+0

Да, я сам это нашел: http://thinkandroid.wordpress.com/2010/01/14/how-to-position-views-properly-in-layouts/ Спасибо в любом случае! – jhulst

+0

Желаемый выходной экран экрана, поставленный в вопрос. Задача решена. – jhulst

0

Просто добавьте android:gravity = "center" к вашей линейной компоновки выше

Смежные вопросы