【问题标题】:How to display RatingBar correctly?如何正确显示 RatingBar?
【发布时间】:2012-04-29 20:30:11
【问题描述】:

我有一个 tabLayout,其中 main.xml:

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
     android:id="@android:id/tabhost"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent">
<LinearLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:padding="5dp">
    <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"/>
    <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">
    </FrameLayout>
</LinearLayout>
</TabHost>

还有相关标签:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:orientation="vertical"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
    >
<TextView
        android:id="@+id/if1"
        android:text="@string/aText"
        android:gravity="center_horizontal"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="3"
        android:visibility="visible"/>

<ImageView
        android:id="@+id/id2"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:visibility="visible"
        android:src="@drawable/sample"
        android:layout_weight="1"

        />

<android.widget.RatingBar android:id="@+id/ratingBar"
                          android:layout_width="wrap_content"
                          android:layout_height="wrap_content"
                          android:layout_gravity="center"
                          android:numStars="5"
                          android:stepSize="1"
                          android:visibility="visible"
        />

<android.widget.Button android:id="@+id/rateButton"
                       android:text="@string/rateButton"
                       android:layout_width="fill_parent"
                       android:layout_height="wrap_content"
                       android:visibility="invisible"
        />
</LinearLayout>

为什么 RatingBar 在我运行 Android 2.3.6 的三星 Galaxy S 上显示为这样?在模拟器中看起来不错。

【问题讨论】:

标签: android android-layout


【解决方案1】:

为什么 RatingBar 在我运行 Android 2.3.6 的三星 Galaxy S 上显示为这样?

因为你没有给它足够的屏幕空间。您只给它一定比例的屏幕空间,并且根据设备分辨率和数据,这还不够。

您不应该依赖android:layout_weight 来帮助您处理应该始终完全可见的东西。 android:layout_weight 适用于本质上可滚动的内容(例如,ListView),因为它们可以适应所需的任何大小。

【讨论】:

  • 好的,谢谢,所以 RatingBar 根本不适合我的屏幕?我想我可以以某种方式使其调整大小以适应屏幕。我想那时我将不得不使用较小的星图。
猜你喜欢
  • 2011-04-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-10-08
  • 1970-01-01
相关资源
最近更新 更多