代码之家  ›  专栏  ›  技术社区  ›  Jakob

如何设置可单击但不可缩放的分级栏?

  •  1
  • Jakob  · 技术社区  · 7 年前

    我想展示一个 AlertDialog 点击我的 RatingBar ,但问题是 评分组件 仍然可以缩放(仍然可以更改评级)。

    我想我可以点击 评分组件 ,但不能缩放。

    在这种情况下

    <RatingBar
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        style="?android:attr/ratingBarStyleSmall"
                        android:isIndicator="false"
                        android:theme="@style/RatingBar"
                        android:rating="5"
                        android:layout_marginTop="2dp"
                        android:id="@+id/showrating"
                        />
    

    单击 评分组件 是有可能的,但也可以缩放。

    在这种情况下

    <RatingBar
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        style="?android:attr/ratingBarStyleSmall"
                        android:isIndicator="true"
                        android:theme="@style/RatingBar"
                        android:rating="5"
                        android:layout_marginTop="2dp"
                        android:id="@+id/showrating"
                        />
    

    无法缩放,但也无法单击。

    在这两种情况下我都达不到我想要的。

    我有个问题 android:isIndicator=""

    1 回复  |  直到 7 年前
        1
  •  1
  •   Alex Charters    7 年前

    你所能做的就是把你的RatingBar包装在一个FrameLayout中:

    <FrameLayout
            android:id="@+id/frame"
            android:clickable="true"
            android:focusable="true"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:onClick="onClick">
            <RatingBar
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        style="?android:attr/ratingBarStyleSmall"
                        android:isIndicator="true"
                        android:theme="@style/RatingBar"
                        android:rating="5"
                        android:layout_marginTop="2dp"
                        android:id="@+id/showrating"
                        />
    </FrameLayout>
    

    然后将AlertDialogue逻辑放入onClick方法:

    public void onClick(View v){
            //AlertDialogue Logic
    }