gpt4 book ai didi

java - 当我轮换应用程序时,评分栏会显示更多星星

转载 作者:行者123 更新时间:2023-12-01 10:09:58 25 4
gpt4 key购买 nike

我的评级栏星星有一个奇怪的问题。

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);

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

最佳答案

我发现问题了!

android:shrinkColumns="1,0" android:stretchColumns="0,1"

将其设置为TableLayout导致了这个奇怪的问题。

感谢大家有兴趣帮助我..

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

25 4 0