2013-03-14 1 views
2

Я пытаюсь установить RatingBar только с 5 звездами, но он расширяется, чтобы заполнить ширину экрана.Невозможно изменить ширину и количество звезд RatingBar

Я обнаружил аналогичные проблемы:

Тем не менее, большую часть времени раствор должен установить ширину, чтобы wrap_content но ширина меня всегда было wrap_content.

Это мой макет. Если вы прокрутите до дна, вы увидите два RatingBar сек:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" > 

    <TableLayout 
     android:id="@+id/add_spot_layout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:shrinkColumns="1" 
     android:stretchColumns="1" > 

     <TableRow 
      android:layout_marginBottom="2sp" 
      android:layout_marginTop="2sp" > 

      <TextView android:text="Distance:" /> 

      <TextView android:id="@+id/distancePopup" /> 
     </TableRow> 

     <TableRow 
      android:layout_marginBottom="2sp" 
      android:layout_marginTop="2sp" > 

      <TextView android:text="Address:" /> 

      <TextView android:id="@+id/addrPopup" /> 
     </TableRow> 

     <TableRow 
      android:layout_marginBottom="2sp" 
      android:layout_marginTop="2sp" > 

      <TextView android:text="Type:" /> 

      <TextView android:id="@+id/typePopup" /> 
     </TableRow> 

     <TableRow 
      android:layout_marginBottom="2sp" 
      android:layout_marginTop="2sp" > 

      <TextView android:text="Terrain:" /> 

      <RatingBar 
       android:id="@+id/terrainPopup" 
       style="?android:attr/ratingBarStyleSmall" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:isIndicator="true" 
       android:max="5" 
       android:numStars="5" 
       android:stepSize="1" /> 
     </TableRow> 

     <TableRow> 

      <TextView android:text="Difficulty:" /> 

      <RatingBar 
       android:id="@+id/difficultyPopup" 
       style="?android:attr/ratingBarStyleSmall" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:isIndicator="true" 
       android:max="5" 
       android:numStars="5" 
       android:stepSize="0.1" /> 
     </TableRow> 

     <TableRow 
      android:layout_marginBottom="2sp" 
      android:layout_marginTop="2sp" > 

      <TextView android:text="Description:" /> 

      <TextView 
       android:id="@+id/descPopup" 
       android:gravity="top" 
       android:lines="2" 
       android:maxLines="2" 
       android:scrollHorizontally="false" /> 
     </TableRow> 
    </TableLayout> 

</ScrollView> 

Это то, что он выглядит следующим образом:

ответ

0

В таблице макете используется как

android:shrinkColumns="1" 
    android:stretchColumns="1" 

Здесь вы сокращаетесь и растягиваете одинаковое количество столбцов.

Я удалил

android:stretchColumns="1" 

И в свою работу для меня.

enter image description here

Окончательный макет

<TableLayout 
    android:id="@+id/add_spot_layout" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:shrinkColumns="1" > 

    <TableRow 
     android:layout_marginBottom="2sp" 
     android:layout_marginTop="2sp" > 

     <TextView android:text="Distance:" /> 

     <TextView android:id="@+id/distancePopup" /> 
    </TableRow> 

    <TableRow 
     android:layout_marginBottom="2sp" 
     android:layout_marginTop="2sp" > 

     <TextView android:text="Address:" /> 

     <TextView android:id="@+id/addrPopup" /> 
    </TableRow> 

    <TableRow 
     android:layout_marginBottom="2sp" 
     android:layout_marginTop="2sp" > 

     <TextView android:text="Type:" /> 

     <TextView android:id="@+id/typePopup" /> 
    </TableRow> 

    <TableRow 
     android:layout_marginBottom="2sp" 
     android:layout_marginTop="2sp" > 

     <TextView android:text="Terrain:" /> 

     <RatingBar 
      android:id="@+id/terrainPopup" 
      style="?android:attr/ratingBarStyleSmall" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:isIndicator="true" 
      android:max="5" 
      android:numStars="5" 
      android:stepSize="1" /> 
    </TableRow> 

    <TableRow> 

     <TextView android:text="Difficulty:" /> 

     <RatingBar 
      android:id="@+id/difficultyPopup" 
      style="?android:attr/ratingBarStyleSmall" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:isIndicator="true" 
      android:max="5" 
      android:numStars="5" 
      android:stepSize="0.1" /> 
    </TableRow> 

    <TableRow 
     android:layout_marginBottom="2sp" 
     android:layout_marginTop="2sp" > 

     <TextView android:text="Description:" /> 

     <TextView 
      android:id="@+id/descPopup" 
      android:gravity="top" 
      android:lines="2" 
      android:maxLines="2" 
      android:scrollHorizontally="false" /> 
    </TableRow> 
</TableLayout> 

1

Для будущих Googlers,

Ответ на Amit помог мне с этой проблемой: Рейтинг виджетов показывает путь слишком много звезд.

Это потому, что виджет должен быть установлен в android:layout_width="wrap_content" для учета числа столбцов.

+0

Это решило для меня - это, если он выше – user43043

3

Я думаю, что это можно решить, вставив RATINGBAR внутри RELATIVELAYOUT. Я думаю, что эта проблема связана с тем, что характер TableLayout заключается в заполнении родителя в любом случае, а RATINGBAR принимает ширину родителя. Поэтому я решил это вложить RATINGBAR внутри RELATIVELAYOUT и установить LAYOUT_WIDTH и LAYOUT_HEIGT на WRAP_CONTENT для обоих (RATINGBAR и RELATIVE LAYOUT). Только в этом случае я смог иметь RATINGBAR внутри TABLELAYOUT.

Надежда помогает;)

0

Использование Relative Layout в качестве родителя или паспортного бара и wrap_content для рейтинга бара будет решить вашу проблему

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

  • Нет связанных вопросов^_^