如何显示行同一图像多个时? [英] How to show same image multiple time in row?

查看:116
本文介绍了如何显示行同一图像多个时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发儿童的应用程序。儿童的基本数学学习与乐趣。

I am developing an application for children. Basic maths for children to learn with fun.

在这个程序我使用苹果的图像​​显示在屏幕上。加法时,他们给第一个输入和第二输入在第一和第二输入指定它应该显示苹果的图像​​。

In this app I am using apple image for displaying on the screen. for addition when they give 1st input and second input it should show apple images as specified in 1st and 2nd input.

时的任何一个知道这个或任何一个有源$ C ​​$ C THN帮我解

Is any one know solution for this or any one having source code thn help me

推荐答案

这是你能做到这一点,很简单,但方式:)

this is the way you can do it ,quite simple though :)

你的XML应该是这样的。

your xml should look like this

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

和你的活动看起来像这样

and you Activity looks like this

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

}

}

这篇关于如何显示行同一图像多个时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆