【问题标题】:How can I set a RatingBar clickable, but not scaleable?如何设置 RatingBar 可点击但不可缩放?
【发布时间】:2018-08-03 02:49:06
【问题描述】:

我想在点击我的RatingBar 时显示AlertDialog,但问题是RatingBar 仍然是可缩放的(仍然可以更改评级)。

我希望我可以点击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,但也可以缩放。

在这种情况下

<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="" 有问题

【问题讨论】:

    标签: java xml android-studio


    【解决方案1】:

    您可以将 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
    }
    

    【讨论】:

    • 我是否需要将 onclick 添加到框架布局或 RatingBar?
    • @Jakob 到 FrameLayout。
    • 谢谢 :) 它有效。如果您认为我问得好,请投票支持我的问题。
    猜你喜欢
    • 1970-01-01
    • 2021-06-21
    • 2013-07-30
    • 2020-01-17
    • 1970-01-01
    • 2016-09-23
    • 1970-01-01
    • 2015-09-19
    • 1970-01-01
    相关资源
    最近更新 更多