繁体   English   中英

旋转应用程序时,评分栏显示的星星更多

[英]Rating bar shows more stars when I rotate my application

我的评分栏星标有这个怪异的问题。

这是我在垂直位置的应用

这是我在水平位置的应用

如您所见,星星完全改变了

这是我的xml文件:

<?xml version="1.0" encoding="utf-8"?>
   <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:background="@drawable/main"
    tools:context="com.example.draganam.blankapp.Nivo1Activity">

    <TableLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:shrinkColumns="1,0" android:stretchColumns="0,1">

        <TableRow
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingTop="50dp">

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/slika0"
                android:src="@drawable/becutan1"
                android:layout_column="0"
                android:layout_marginRight="40px" />

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/slika1"
                android:src="@drawable/blizoo1"
                android:layout_column="1" />
        </TableRow>

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <RatingBar
                android:id="@+id/rb0"
                style="?android:attr/ratingBarStyleIndicator"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:numStars="5"
                android:stepSize="1.0"
                android:isIndicator="true"
                android:scaleX="0.7"
                android:scaleY="0.7"/>

            <RatingBar
                android:id="@+id/rb1"
                style="?android:attr/ratingBarStyleIndicator"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:numStars="5"
                android:stepSize="1.0"
                android:isIndicator="true"
                android:scaleX="0.7"
                android:scaleY="0.7"/>
        </TableRow>

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:paddingTop="50dp">

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/slika2"
                android:src="@drawable/brilijant1"
                android:layout_column="0"
                android:layout_marginRight="40px" />

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/slika3"
                android:src="@drawable/vitaminka1"
                android:layout_column="1" />
        </TableRow>
        <TableRow
            android:layout_width="match_parent"
            android:layout_height="match_parent">
        <RatingBar
            android:id="@+id/rb2"
            style="?android:attr/ratingBarStyleIndicator"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:numStars="5"
            android:stepSize="1.0"
            android:isIndicator="true"
            android:scaleX="0.7"
            android:scaleY="0.7"/>

        <RatingBar
            android:id="@+id/rb3"
            style="?android:attr/ratingBarStyleIndicator"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:numStars="5"
            android:stepSize="1.0"
            android:isIndicator="true"
            android:scaleX="0.7"
            android:scaleY="0.7"/>
    </TableRow>

    </TableLayout>
</RelativeLayout>

这是我的Java代码:

Context ctx2 = this;
String[][] arrayWithInformations = new String[5][];
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_nivo1);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    DatabaseOperations databaseOperations = new DatabaseOperations(ctx2);
    Cursor cursorLogo = databaseOperations.getInformationsForLogos(databaseOperations);
    // looping through all rows and adding to list
    Integer i = 0;
    if (cursorLogo.moveToFirst()) {
        do {
            String[] helperArray = {cursorLogo.getString(0),cursorLogo.getString(1),cursorLogo.getString(2),cursorLogo.getString(3),
                    cursorLogo.getString(4),cursorLogo.getString(5)};
            arrayWithInformations[i] = helperArray;
            i++;

        } while (cursorLogo.moveToNext());
    }
    int firstRating = Integer.parseInt(arrayWithInformations[0][4]);
    int secondRating = Integer.parseInt(arrayWithInformations[1][4]);
    int thirdRating = Integer.parseInt(arrayWithInformations[2][4]);
    int fourthRating = Integer.parseInt(arrayWithInformations[3][4]);
    RatingBar rb0 = (RatingBar) findViewById(R.id.rb0);
    rb0.setRating(firstRating);
    RatingBar rb1 = (RatingBar) findViewById(R.id.rb1);
    rb1.setRating(secondRating);
    RatingBar rb2 = (RatingBar) findViewById(R.id.rb2);
    rb2.setRating(thirdRating);
    RatingBar rb3 = (RatingBar) findViewById(R.id.rb3);
    rb3.setRating(fourthRating);

我从数据库文件中获得了评级值,并且一切正常,星星还可以,但是当我旋转手机时,它们都是错误的。 我知道that当u旋转手机的当前活动被再次加载,但它是相同的代码,它加载错误。 也许是星星在增加。.我听起来可能很有趣,但是我不知道出了什么问题。 有人请给我带头。

我发现了问题!

android:shrinkColumns =“ 1,0” android:stretchColumns =“ 0,1”

将此设置为TableLayout会导致此奇怪的问题。

谢谢大家对我的帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM