Выровняйте рейтинг по шкале справа

1

Я пытаюсь добавить Ratingbar в строку listview-, которая отображает изображение и текст. Моя проблема в том, что когда я добавляю рейтингбар, я не могу заставить его выравниваться вправо. Он либо заполняет доступную область, либо выравнивается слева.

Моя строка list- определяется следующим образом:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content">
<ImageView  
    android:id="@+id/picture"
    android:layout_width="64px"
    android:layout_height="64px"
    android:paddingLeft="3px"
    ></ImageView>
<TextView 
    android:id="@+id/drinkName" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"
    android:textSize="25px">
    </TextView>
<RatingBar
    android:id="@+id/rating"
    android:layout_gravity="right"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    style="?android:attr/ratingBarStyleSmall">
    </RatingBar>
</LinearLayout>

Любые идеи?

Спасибо заранее Roland

Теги:
alignment
listview

3 ответа

2
Лучший ответ

Три небольших изменения:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content">
<ImageView  
    android:id="@+id/picture"
    android:layout_width="64px"
    android:layout_height="64px"
    android:paddingLeft="3px"
    ></ImageView>
<TextView 
    android:id="@+id/drinkName" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:textSize="25px">
    </TextView>
<RatingBar
    android:id="@+id/rating"
    android:layout_gravity="right"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    style="?android:attr/ratingBarStyleSmall">
    </RatingBar>
</LinearLayout>
1

Вы можете использовать RelativeLayout... например:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content">
<ImageView  
    android:id="@+id/picture"
    android:layout_width="64px"
    android:layout_height="64px"
    android:paddingLeft="3px"
></ImageView>
<TextView 
android:id="@+id/drinkName" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content"
android:textSize="25px">
</TextView>
<RelativeLayout android:layout_width="wrap_content" android:id="@+id/relativeLayout1" android:layout_height="match_parent">
    <RatingBar android:layout_width="wrap_content" android:id="@+id/rating" android:layout_height="wrap_content" style="?android:attr/ratingBarStyleSmall" android:layout_alignParentRight="true"></RatingBar>
</RelativeLayout>
</LinearLayout>
0

Вы пробовали gravity -attribute? Кроме того, вы не должны использовать значения pixel-. Это заставит ваш макет выглядеть плохо на устройствах с другим разрешением screen-.

Ещё вопросы

Сообщество Overcoder
Наверх
Меню