誰かが私を助けてくれる?テキストビューの結果をイメージビューに表示できません。誰か助けてください。テキストビューの結果をイメージビューで表示したいと思います。私は何度も変更して見直しを試みましたが、間違っていたものはまだ見つけられません。イメージビューでテキストビューに表示
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="sg.edu.rp.c346.lovecalculator.MainActivity">
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_below="@+id/b_calculate"
android:layout_centerHorizontal="true"
android:scaleType="centerInside"
android:src="@drawable/heart" />
<EditText
android:id="@+id/et_female"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:hint="Female name" />
<EditText
android:id="@+id/et_male"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/et_female"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:hint="Male name" />
<Button
android:id="@+id/b_calculate"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/et_male"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:text="Calculate" />
<TextView
android:id="@+id/tv_result"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignTop="@+id/imageView"
android:layout_centerHorizontal="true"
android:gravity="center"
android:text=""
android:textColor="#ef3737"
android:textSize="32dp" />
public class MainActivity extends AppCompatActivity {
EditText et_female, et_male;
Button b_calculate;
TextView tv_result;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
et_female = (EditText) findViewById(R.id.et_female);
et_male = (EditText) findViewById(R.id.et_male);
b_calculate = (Button) findViewById(R.id.b_calculate);
tv_result = (TextView) findViewById(R.id.tv_result);
b_calculate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (et_female.getText().toString().equals("")
&& et_male.getText().toString().equals("")) {
String female = et_female.getText().toString();
String male = et_male.getText().toString();
Calendar c = Calendar.getInstance();
String day = String.valueOf(c.get(Calendar.DAY_OF_MONTH));
String month = String.valueOf(c.get(Calendar.MONTH));
String year = String.valueOf(c.get(Calendar.YEAR));
String result_string = female + male + day + month + year;
result_string = result_string.toLowerCase();
result_string = result_string.trim();
int seed = result_string.hashCode();
Random r = new Random(seed);
tv_result.setText((r.nextInt(100) + 1) + "%");
}
}
});
}
}
MainActivityのImageViewは –
です。アクティビティにimageviewをどこに追加しましたか? –
画像を配置したい場所は?上? –