2017-02-07 16 views
-2

誰かが私を助けてくれる?テキストビューの結果をイメージビューに表示できません。誰か助けてください。テキストビューの結果をイメージビューで表示したいと思います。私は何度も変更して見直しを試みましたが、間違っていたものはまだ見つけられません。イメージビューでテキストビューに表示

<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) + "%"); 

      } 

     } 
    }); 


} 

}

+1

MainActivityのImageViewは –

+0

です。アクティビティにimageviewをどこに追加しましたか? –

+0

画像を配置したい場所は?上? –

答えて

0

あなたがのTextViewの背景を設定することができます。

この

<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"> 


    <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="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/b_calculate" 
     android:gravity="center" 
     android:layout_centerHorizontal="true" 
     android:background="@drawable/heart" 
     android:text="510" 
     android:padding="10dp" 
     android:textColor="#ef3737" 
     android:textSize="32dp" /> 
</RelativeLayout> 
+0

しかし、私はテキストを設定することができません、私はボタンを押したときに変更されません。 – user7322413

0

はそうのようなフレームレイアウトを使用してみてくださいTextViewには上記になりますので

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <ImageView 
     android:src="@drawable/ic_launcher" 
     android:scaleType="fitCenter" 
     android:layout_height="250px" 
     android:layout_width="250px"/> 

    <TextView 
     android:text="Frame Demo" 
     android:textSize="30px" 
     android:textStyle="bold" 
     android:layout_height="fill_parent" 
     android:layout_width="fill_parent" 
     android:gravity="center"/> 
</FrameLayout> 

変更の大きさに応じて、フレームのレイアウトが自動的に最初の子の上に第二子を配置しますイメージビューとそれの後ろに隠されていない。

お楽しみください。

関連する問題