私は子供向けのアプリケーションを開発しています。子供たちが楽しく学ぶための基本的な数学。
このアプリでは、画面に表示するためにアップルの画像を使用しています。さらに、1番目と2番目の入力を与えると、1番目と2番目の入力で指定されたアップルの画像が表示されます。
これに対する解決策を知っている人はいますか、それともソースコードを持っている人は私を助けてくれますか
私は子供向けのアプリケーションを開発しています。子供たちが楽しく学ぶための基本的な数学。
このアプリでは、画面に表示するためにアップルの画像を使用しています。さらに、1番目と2番目の入力を与えると、1番目と2番目の入力で指定されたアップルの画像が表示されます。
これに対する解決策を知っている人はいますか、それともソースコードを持っている人は私を助けてくれますか
これはあなたがそれを行うことができる方法ですが、非常に簡単です:)
xmlは次のようになります
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/input1" />
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/input2" />
<Button android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/button"
android:text="Result"/>
<HorizontalScrollView
android:id="@+id/scroll1"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout android:id="@+id/linear1"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</LinearLayout>
</HorizontalScrollView>
<HorizontalScrollView
android:id="@+id/scroll2"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/linear2"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</LinearLayout>
</HorizontalScrollView>
<HorizontalScrollView
android:id="@+id/scroll3"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/linear3"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>
アクティビティは次のようになります
package com.example.stackanswer;
import android.os.Bundle;
import android.app.ActionBar.LayoutParams;
import android.app.Activity;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.HorizontalScrollView;
import android.widget.ImageView;
import android.widget.LinearLayout;
public class AppleActivity extends Activity {
private LinearLayout linear1;
private LinearLayout linear2;
private LinearLayout linear3;
private HorizontalScrollView scrollbar1;
private HorizontalScrollView scrollbar2;
private HorizontalScrollView scrollbar3;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_apple);
final EditText input1 = (EditText)findViewById(R.id.input1);
final EditText input2 = (EditText)findViewById(R.id.input2);
scrollbar1 = (HorizontalScrollView)findViewById(R.id.scroll1);
scrollbar2 = (HorizontalScrollView)findViewById(R.id.scroll2);
scrollbar3 = (HorizontalScrollView)findViewById(R.id.scroll3);
linear1 = (LinearLayout)findViewById(R.id.linear1);
linear2 = (LinearLayout)findViewById(R.id.linear2);
linear3 = (LinearLayout)findViewById(R.id.linear3);
Button output = (Button)findViewById(R.id.button);
output.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
String input1A = input1.getText().toString();
String input1B = input2.getText().toString();
int value1 = Integer.parseInt(input1A);
int value2 = Integer.parseInt(input1B);
Log.i("1",""+value1);
Log.i("2",""+value2);
linear1.removeAllViews();
linear2.removeAllViews();
linear3.removeAllViews();
linear1.setScrollContainer(true);
ImageView image ;
for(int i=0;i<value1;i++){
image = new ImageView(getApplicationContext());
image.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT) );
image.setImageResource(R.drawable.ic_launcher);
Log.i("i", i+"");
linear1.addView(image);
scrollbar1.fullScroll(HorizontalScrollView.FOCUS_RIGHT);
}
for(int i=0;i<value2;i++){
image = new ImageView(getApplicationContext());
image.setImageResource(R.drawable.ic_launcher);
Log.i("i", i+"");
linear2.addView(image);
scrollbar2.fullScroll(HorizontalScrollView.FOCUS_RIGHT);
}
int sum = value1+value2;
for(int i=0;i<sum;i++){
image = new ImageView(getApplicationContext());
image.setImageResource(R.drawable.ic_launcher);
Log.i("i", i+"");
linear3.addView(image);
scrollbar3.fullScroll(HorizontalScrollView.FOCUS_RIGHT);
}
}
});
}
}
ここに完全なソースコード