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

This is my app in vertical position

This is my app in horizontal position

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

这是我的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当您旋转手机时,当前活动会再次加载,但这是相同的代码,并且加载错误。也许是星星在增加。.我听起来可能很有趣,但是我不知道出了什么问题。有人请给我带头。

最佳答案

我发现了问题!


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


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

谢谢大家对我的帮助。

关于java - 旋转应用程序时,评分栏显示的星星更多,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36186301/

10-09 12:39