RatingBar不会出现在ListView中

时间:2014-05-22 23:01:07

标签: android listview ratingbar

我有一个带有一个RatingBar和两个textview的ListView,当我在模拟器中运行应用程序时,它显示正确,但是当我尝试在我的Galaxy S3上运行它时,ratingbar不会出现在listview中,只显示文字视图。

任何人都知道我应该做些什么来纠正它?

ItemLista

    public class ItemLista {
private String nome;
private String comentario;
private float nota;

public ItemLista(String nome, String comentario, float nota) {
    super();
    this.nome = nome;
    this.comentario = comentario;
    this.nota = nota;
}

public String getNome() {
    return nome;
}
public void setNome(String nome) {
    this.nome = nome;
}
public String getComentario() {
    return comentario;
}
public void setComentario(String comentario) {
    this.comentario = comentario;
}
public float getNota() {
    return nota;
}
public void setNota(float nota) {
    this.nota = nota;
}   
}

ComentariosAdapter

    public class ComentariosAdapter extends ArrayAdapter<ItemLista> {
private final Context context;        
    private final ArrayList<ItemLista> itemsArrayList;

    public ComentariosAdapter(Context context, ArrayList<ItemLista> itemsArrayList) {

    super(context, R.layout.item_lista_comentarios, itemsArrayList);

    this.context = context;
    this.itemsArrayList = itemsArrayList;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

    // 1. Create inflater 
    LayoutInflater inflater = (LayoutInflater) context
        .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    // 2. Get rowView from inflater
    View rowView = inflater.inflate(R.layout.item_lista_comentarios, parent, false);

    // 3. Get the two text view from the rowView
    TextView nameView = (TextView) rowView.findViewById(R.id.txtUsuario);
    TextView comentarioView = (TextView) rowView.findViewById(R.id.txtComentario);
    RatingBar rankView = (RatingBar) rowView.findViewById(R.id.rankSmall);

    // 4. Set the text for textView 
    nameView.setText(itemsArrayList.get(position).getNome());
    comentarioView.setText(itemsArrayList.get(position).getComentario());
    rankView.setRating(itemsArrayList.get(position).getNota());
    rankView.setIsIndicator(true);

    // 5. return rowView
    return rowView;
    }
    }

TabDetalhes

    public View onCreateView(LayoutInflater inflater, ViewGroup container,
    Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View V = inflater.inflate(R.layout.tab_detalhes, container, false);

    RatingBar rank = (RatingBar) V.findViewById(R.id.rank);
    rank.setRating((float) 3.5);
    rank.setIsIndicator(true);

    ComentariosAdapter adapter = new ComentariosAdapter(V.getContext(), dados());

    ListView lista = (ListView) V.findViewById(R.id.listaComentarios);

    lista.setAdapter(adapter);             
    return V;
    }

private ArrayList<ItemLista> dados(){
    ArrayList<ItemLista> items = new ArrayList<ItemLista>();
    items.add(new ItemLista("Lucas Freitas","Lugar legal, ambiente confortavel", 4.5f));
    items.add(new ItemLista("Eduardo Bonight","Cara, comi tanto que pediram pra eu sair D:", 3.5f));
    items.add(new ItemLista("Guilherme Garcia","O que eu to fazendo aqui ? o.O", 2.5f));
    items.add(new ItemLista("Caique Sampaio","Mano...eu tava upando ¬¬", 2.5f));

    return items;
    }
    }

item_lista_comentario.xml

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="left"
    android:orientation="vertical" >

    <RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <RatingBar
        android:id="@+id/rankSmall"
        android:numStars="5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="-60dp"
        android:layout_marginTop="-5dp"
        android:scaleX="0.4"
        android:scaleY="0.4"
        style="@style/rankRating" />

    <TextView
        android:id="@+id/txtUsuario"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="8dp"
        android:layout_marginLeft="120dp"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textColor="#565656"
        android:textAlignment="center"
        android:textSize="20sp"  />

</RelativeLayout>

<TextView
    android:id="@+id/txtComentario"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="8dp"
    android:layout_marginLeft="12dp"
    android:layout_marginBottom="8dp"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:textColor="#565656"
    android:textAlignment="center"
    android:textSize="15sp"  />

</LinearLayout>

1 个答案:

答案 0 :(得分:0)

RatingBar的大小是多少?你给它带有负边距-60dp-5dp,所以我的猜测是你的RatingBar被移出可见区域。

根据this question猜猜。