0
隨機選擇imageview在同一時間一個按鈕有其他三個是錯誤的。 imageView會隨機顯示照片,但不會調整按鈕。我該怎麼辦?我做imageView隨機選擇,但不調整其他。 see this imageAndroid隨機圖像視圖鏈接到匹配按鈕
RES /佈局/ activity_letter_test_first
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_letter_test_first"
android:layout_width="match_parent"
android:layout_height="match_parent"
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:orientation="vertical"
tools:context="com.example.nayemuzzaman.learning.LetterTestFirst">
<TextView
android:text="Try to find A "
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textView2"
android:textAppearance="@style/TextAppearance.AppCompat.Display1" />
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@drawable/a"
android:id="@+id/imgViewRandom"
android:onClick="imageLetterRandom" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:text="Button"
android:layout_width="182dp"
android:layout_height="wrap_content"
android:id="@+id/button" />
<Button
android:text="Button"
android:layout_width="171dp"
android:layout_height="wrap_content"
android:id="@+id/button4" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="59dp">
<Button
android:text="Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button5"
android:layout_weight="1.14" />
<Button
android:text="Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button6"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
的Java/com.example.nayemuzzaman.learning/LetterTestFirst
package com.example.nayemuzzaman.learning;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import java.util.Random;
public class LetterTestFirst extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_letter_test_first);
final int[] phtLetter={R.drawable.a, R.drawable.b, R.drawable.c}; //total picture add
final ImageView imgViewRnd=(ImageView) findViewById(R.id.imgViewRandom); //imageView address
final Random ranLtr=new Random();
int imgLetter=ranLtr.nextInt(phtLetter.length);
imgViewRnd.setImageResource(phtLetter[imgLetter]);
imgViewRnd.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
int tlLetter = ranLtr.nextInt(phtLetter.length); //total length letter photos & random selected photos.
imgViewRnd.setImageResource(phtLetter[tlLetter]);
}
});
}
}
我投票結束這個問題(但我沒有downvote它),因爲它似乎無法挽回。由於這是你在SO上的首次亮相,所以我建議你告訴你自己如何寫出一個清晰並且主題化的問題,並且你刪除這個問題並且完全重新表達它。我相信你有一個我們可以提供幫助的有效問題。乾杯! –
請給我鏈接,如果你還記得 – Nayemuzzaman
https://stackoverflow.com/help/how-to-ask –