本人是新手 求高手解决。
解决方案
40
不多说了,直接贴代码
layout_main(activity_main.xml):
<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”
tools:context=”${relativePackage}.${activityClass}” >
<ImageView
android:id=”@+id/image”
android:layout_width=”match_parent”
android:layout_height=”match_parent”
android:visibility=”gone” />
<ListView
android:id=”@+id/list”
android:layout_width=”match_parent”
android:layout_height=”wrap_content” >
</ListView>
</RelativeLayout>
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
layout_item(item.xml):
<?xml version=”1.0″ encoding=”utf-8″?>
<LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android”
android:layout_width=”match_parent”
android:layout_height=”match_parent”
android:orientation=”vertical” >
<ImageView
android:id=”@+id/item_image”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content” />
</LinearLayout>
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
MainActivity(MainActivity):
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
public class MainActivity extends Activity {
ListView listView;
ImageView imageView;
int[] images = { R.drawable.application_platform_1, R.drawable.application_platform_2,
R.drawable.application_platform_3, R.drawable.application_platform_4,
R.drawable.application_platform_5, R.drawable.application_platform_6,
R.drawable.application_platform_7, R.drawable.application_platform_8,
R.drawable.application_platform_9, R.drawable.application_platform_10 };
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageView = (ImageView) findViewById(R.id.image);
listView = (ListView) findViewById(R.id.list);
listView.setAdapter(new BaseAdapter() {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = MainActivity.this.getLayoutInflater()
.inflate(R.layout.item, null);
}
ImageView imageView = (ImageView) convertView
.findViewById(R.id.item_image);
imageView.setImageResource(images[position]);
return convertView;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public Object getItem(int position) {
return position;
}
@Override
public int getCount() {
return 10;
}
});
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
imageView.setVisibility(View.VISIBLE);
listView.setVisibility(View.GONE);
imageView.setImageResource(images[position]);
}
});
imageView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
imageView.setVisibility(View.GONE);
listView.setVisibility(View.VISIBLE);
}
});
}
}
layout_main(activity_main.xml):
<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”
tools:context=”${relativePackage}.${activityClass}” >
<ImageView
android:id=”@+id/image”
android:layout_width=”match_parent”
android:layout_height=”match_parent”
android:visibility=”gone” />
<ListView
android:id=”@+id/list”
android:layout_width=”match_parent”
android:layout_height=”wrap_content” >
</ListView>
</RelativeLayout>
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
layout_item(item.xml):
<?xml version=”1.0″ encoding=”utf-8″?>
<LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android”
android:layout_width=”match_parent”
android:layout_height=”match_parent”
android:orientation=”vertical” >
<ImageView
android:id=”@+id/item_image”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content” />
</LinearLayout>
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
MainActivity(MainActivity):
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
public class MainActivity extends Activity {
ListView listView;
ImageView imageView;
int[] images = { R.drawable.application_platform_1, R.drawable.application_platform_2,
R.drawable.application_platform_3, R.drawable.application_platform_4,
R.drawable.application_platform_5, R.drawable.application_platform_6,
R.drawable.application_platform_7, R.drawable.application_platform_8,
R.drawable.application_platform_9, R.drawable.application_platform_10 };
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageView = (ImageView) findViewById(R.id.image);
listView = (ListView) findViewById(R.id.list);
listView.setAdapter(new BaseAdapter() {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = MainActivity.this.getLayoutInflater()
.inflate(R.layout.item, null);
}
ImageView imageView = (ImageView) convertView
.findViewById(R.id.item_image);
imageView.setImageResource(images[position]);
return convertView;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public Object getItem(int position) {
return position;
}
@Override
public int getCount() {
return 10;
}
});
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
imageView.setVisibility(View.VISIBLE);
listView.setVisibility(View.GONE);
imageView.setImageResource(images[position]);
}
});
imageView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
imageView.setVisibility(View.GONE);
listView.setVisibility(View.VISIBLE);
}
});
}
}