Android评分栏超出了对话框的范围

时间:2019-04-16 05:53:29

标签: android android-layout

the rating bar inside my dialog box is going out of bounds enter image description here

 final AlertDialog.Builder popDialog = new AlertDialog.Builder(ExercisesActivity.this);
 final RatingBar rb = new RatingBar(ExercisesActivity.this);
 popDialog.setIcon(android.R.drawable.btn_star_big_on);
 rb.setMax(6);
 popDialog.setTitle("Set Difficulty");
 popDialog.setView(rb);
 // Button OK
 popDialog.setPositiveButton(android.R.string.ok,
       new DialogInterface.OnClickListener() {
       public void onClick(DialogInterface dialog, int which) {
              //do things
       }

 });
 popDialog.create();
 popDialog.show();

setMax()无效

4 个答案:

答案 0 :(得分:0)

首先指定高度和宽度:

 LinearLayout linearLayout = new LinearLayout(this);
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT
    );

linearLayout.addView(rb);

设置要显示的星星数setNumStars(x)。为了正确显示这些内容,建议此小部件的布局宽度为自动换行内容。 喜欢:

rb.setNumStars(6);

答案 1 :(得分:0)

您可以这样设置自己的宽度:

 rb.getLayoutParams().width = WindowManager.LayoutParams.MATCH_PARENT; 
// you can also use WRAP_CONTENT but I think that for your dialog MATCH_PARENT is better

答案 2 :(得分:0)

setMax()方法定义了用户可以选择的最大启动次数。

根据您的查询,我希望您正在设置要显示的星星数。

因此在您的代码中删除

<properties>
    <java.version>1.8</java.version>
    <spring-boot-admin.version>2.1.4</spring-boot-admin.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
    </dependency>
    <dependency>
        <groupId>de.codecentric</groupId>
        <artifactId>spring-boot-admin-starter-server</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>de.codecentric</groupId>
            <artifactId>spring-boot-admin-dependencies</artifactId>
            <version>${spring-boot-admin.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

替换
$("#campiagn_search_id").keyup(function(){alert($(this).val());});

希望四给你一个解决方案:)

答案 3 :(得分:0)

如果直接在RatingBar中添加AlertDialog,则将在我们动态生成Ratingbar且未设置宽度的情况下导致有线输出。

您可以通过将LayoutParams设置为RatingBar并将RatingBar添加到LinearLayout并将LinearLayout视图添加到{{1 }}。

检查以下示例:

AlertDialog

输出:

enter image description here