LinearLayout с гравитацией и весом - PullRequest
1 голос
/ 15 сентября 2011

В моем LinearLayout использование веса в сочетании с гравитацией вызывает обратный эффект веса.Макет:

<LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content"
    android:layout_weight="0.2">
    <TextView android:id="@+id/feedfragmentTitle" android:layout_height="wrap_content" android:layout_width="fill_parent" android:layout_weight="8"/>
    <TextView android:id="@+id/feedfragmentDate" android:layout_height="wrap_content" android:gravity="right" android:layout_width="fill_parent" android:layout_weight="2"/>
</LinearLayout>

Данный LinearLayout содержит заголовок, который должен приблизительно занять 80% макета и дату + время с 20%.Дата + Время должны иметь право тяжести.Размещенный мною макет, к сожалению, не работает, и если я играю с весом параметров, результат будет инвертированным.

Есть ли другой способ получить результаты, не меняя веса?

Ответы [ 2 ]

7 голосов
/ 15 сентября 2011

Когда вы используете свойство layout_weight, вам нужно сделать соответствующую высоту или ширину, как 0dip

, попробуйте это

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="horizontal" android:layout_width="fill_parent" 
    android:layout_height="wrap_content">
    <TextView android:id="@+id/feedfragmentTitle" 
        android:layout_height="wrap_content" android:layout_width="0dip" 
        android:layout_weight="8" android:text="sdfdfsfsd"/>
    <TextView android:text="aass" android:id="@+id/feedfragmentDate" 
        android:layout_height="wrap_content" 
       android:gravity="right" android:layout_width="0dip" 
       android:layout_weight="2"/>
</LinearLayout>
0 голосов
/ 15 сентября 2011

Попробуйте вот так

<LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content">
<TextView android:id="@+id/feedfragmentTitle" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_gravity="left"/>
<TextView android:id="@+id/feedfragmentDate" android:layout_height="wrap_content" android:layout_gravity="right" android:layout_width="wrap_content" />
</LinearLayout>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...