如何从滚动视图中检索特定的图像...
在我的应用程序中,我创建了两个活动 .... Activity 1,Activity2 及其对应的 xml1,xml2
ACTIVITY 1:
package com.scroll;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button b1=(Button)findViewById(R.id.button1);
b1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent in=new Intent(MainActivity.this,Act.class);
startActivity(in);
}
});
Button b2=(Button)findViewById(R.id.button2);
b2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent in=new Intent(MainActivity.this,Act.class);
startActivity(in);
}
});
Button b3=(Button)findViewById(R.id.button3);
b3.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent in=new Intent(MainActivity.this,Act.class);
startActivity(in);
}
});
}
}
活动2:打包com.scroll;
import android.os.Bundle;
import android.app.Activity;
public class Act extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
XML 1:
<LinearLayout 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: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=".MainActivity" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="56dp"
android:layout_y="75dp"
android:text="Button" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="56dp"
android:layout_y="75dp"
android:text="Button" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="56dp"
android:layout_y="75dp"
android:text="Button" />
</LinearLayout>
XML 2:
<AbsoluteLayout 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: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=".MainActivity" >
<HorizontalScrollView
android:id="@+id/horizontalScrollView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="-11dp"
android:layout_y="-2dp" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="566dp"
android:layout_height="wrap_content"
android:layout_x="-14dp"
android:layout_y="-6dp"
android:src="@drawable/bear" />
<ImageView
android:id="@+id/imageView2"
android:layout_width="566dp"
android:layout_height="wrap_content"
android:layout_x="-14dp"
android:layout_y="-6dp"
android:src="@drawable/fox" />
<ImageView
android:id="@+id/imageView3"
android:layout_width="566dp"
android:layout_height="wrap_content"
android:layout_x="-14dp"
android:layout_y="-6dp"
android:src="@drawable/goat" />
</LinearLayout>
</HorizontalScrollView>
当我选择按钮 2 时,应该在滚动视图中打开 IMAGEVIEW2 ......当我选择按钮 3 时,应该打开 IMAGEVIEW3 ......怎么做......请帮我解决这个问题......