如何在中央Android上的RatingBar [英] How to center a RatingBar in Android

查看:414
本文介绍了如何在中央Android上的RatingBar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建一个自定义的RatingBar在这里给出的堆栈溢出教程的一个描述和它的寻找伟大,问题是与图像的定心。这里是我得到了什么:

I have created a custom RatingBar as described in one of the tutorials given here on stack-overflow and it's looking great, the problem is with the centering of the image. here is what I've got:

正如你可以看到的TextView在的LinearLayout垂直居中,但的RatingBar是在它的顶部。下面是这个形象我的XML code:

As you can see the TextView is centered vertically in the LinearLayout, but the RatingBar is at the top of it. Here is my xml code of this image:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/scrollView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:foregroundGravity="center" >

    <LinearLayout
        android:layout_width="320dp"
        android:layout_height="match_parent"
        android:gravity="center" >

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="TextView" />

        <RatingBar
            android:id="@+id/ratingBar1"
            style="@style/starsRatingBar"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:numStars="5"
            android:rating="2.3"
            android:stepSize="1" />

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="right"
            android:src="@drawable/ic_launcher" />

    </LinearLayout>

</ScrollView>

下面是造型的code:

Here is the code of the styling:

<style name="starsRatingBar" parent="@android:style/Widget.RatingBar">
        <item name="android:progressDrawable">@drawable/star_ratingbar_full</item>
        <item name="android:minHeight">36dip</item>
        <item name="android:maxHeight">36dip</item>
    </style>

在的RatingBar任何想法,将apprisiated!

Any ideas in the RatingBar would be apprisiated!

感谢

推荐答案

好吧,我想我已经知道了。

Ok, I think I've got it.

问题的关键是滚动型:它会自动使事情变得紧凑,除非你明确告诉它,否则。在滚动视图,设置

The key issue is the ScrollView: it automatically makes things compact, unless you specifically tell it otherwise. In the scroll view, set

android:fillViewport="true"

要使其使用的可用空间。

to make it use the space available.

这篇关于如何在中央Android上的RatingBar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆