我怎样才能在每个imagaview下面放置文字

时间:2011-09-30 10:14:24

标签: android imageview imagebutton android-imageview horizontalscrollview

在我的项目中,我使用图像作为horizo​​ntalscrollview中的按钮。当我点击图像时,它会显示horizantalscrollview上方的图像。我想要的是当我点击它时在图像下显示描述文本。可以帮忙吗?

这是我的xml文件。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/LinearLayout01"
android:layout_width="match_parent" android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:orientation="vertical" android:background="@color/white">

<ImageView android:layout_gravity="center" android:src="@drawable/a1"
    android:layout_height="200dp" android:id="@+id/IVdisplay"
    android:layout_width="200dp"></ImageView>

<TextView android:layout_width="wrap_content"
    android:id="@+id/Aciklama"
    android:layout_height="wrap_content" 
    android:layout_gravity="center"
    android:background="#AA000000" android:textColor="#ffffffff"
    android:text="fghhhhhhhhhhhhhhtyuyjhjkghklşklşkl" 
     />
<HorizontalScrollView android:layout_height="wrap_content"
    android:layout_width="fill_parent"
    android:layout_gravity="bottom">
    <LinearLayout android:layout_gravity="bottom"
        android:orientation="horizontal" android:layout_width="fill_parent"
        android:layout_height="wrap_content">
        <ImageView android:src="@drawable/a1"
            android:layout_height="125dp" android:id="@+id/IVimage1"
            android:layout_width="125dp" android:padding="15dp"></ImageView>
        <ImageView android:src="@drawable/a2"
            android:layout_height="125dp" android:id="@+id/IVimage2"
            android:layout_width="125dp" android:padding="15dp"></ImageView>
        <ImageView android:src="@drawable/a3"
            android:layout_height="125dp" android:id="@+id/IVimage3"
            android:layout_width="125dp" android:padding="15dp"></ImageView>
        <ImageView android:src="@drawable/a4"
            android:layout_height="125dp" android:id="@+id/IVimage4"
            android:layout_width="125dp" android:padding="15dp"></ImageView>
        <ImageView android:src="@drawable/a5"
            android:layout_height="125dp" android:id="@+id/IVimage5"
            android:layout_width="125dp" android:padding="15dp"></ImageView>
        <ImageView android:src="@drawable/a6"
            android:layout_height="125dp" android:id="@+id/IVimage6"
            android:layout_width="125dp" android:padding="15dp"></ImageView>
        <ImageView android:src="@drawable/a7"
            android:layout_height="125dp" android:id="@+id/IVimage7"
            android:layout_width="125dp" android:padding="15dp"></ImageView>
        <ImageView android:src="@drawable/a8"
            android:layout_height="125dp" android:id="@+id/IVimage8"
            android:layout_width="125dp" android:padding="15dp">
</ImageView>
</LinearLayout></HorizontalScrollView></LinearLayout>

这是我的java文件。

    import com.google.ads.AdRequest;
import com.google.ads.AdView;

import android.app.Activity;

import android.os.Bundle;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.ImageView;


public class varningsmarken extends Activity implements View, OnClickListener {

    ImageView display;
/** Called when the activity is first created. */

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.varningsmarken);
AdView ad = (AdView) findViewById(R.id.adView2);
ad.loadAd(new AdRequest());

    display = (ImageView) findViewById (R.id.IVdisplay);
    ImageView image1 = (ImageView) findViewById (R.id.IVimage1);
    ImageView image2 = (ImageView) findViewById (R.id.IVimage2);
    ImageView image3 = (ImageView) findViewById (R.id.IVimage3);
    ImageView image4 = (ImageView) findViewById (R.id.IVimage4);
    ImageView image5 = (ImageView) findViewById (R.id.IVimage5);
    ImageView image6 = (ImageView) findViewById (R.id.IVimage6);
    ImageView image7 = (ImageView) findViewById (R.id.IVimage7);
    ImageView image8 = (ImageView) findViewById (R.id.IVimage8);
    ImageView image9 = (ImageView) findViewById (R.id.IVimage9);
    ImageView image10 = (ImageView) findViewById (R.id.IVimage10);
    ImageView image11 = (ImageView) findViewById (R.id.IVimage11);
    ImageView image12 = (ImageView) findViewById (R.id.IVimage12);
    ImageView image13 = (ImageView) findViewById (R.id.IVimage13);
    ImageView image14 = (ImageView) findViewById (R.id.IVimage14);
    ImageView image15 = (ImageView) findViewById (R.id.IVimage15);
    ImageView image16 = (ImageView) findViewById (R.id.IVimage16);
    ImageView image17 = (ImageView) findViewById (R.id.IVimage17);
    ImageView image18 = (ImageView) findViewById (R.id.IVimage18);
    ImageView image19 = (ImageView) findViewById (R.id.IVimage19);
    image1.setOnClickListener(this);
    image2.setOnClickListener(this);
    image3.setOnClickListener(this);
    image4.setOnClickListener(this);
    image5.setOnClickListener(this);
    image6.setOnClickListener(this);
    image7.setOnClickListener(this);
    image8.setOnClickListener(this);
    image9.setOnClickListener(this);
    image10.setOnClickListener(this);
    image11.setOnClickListener(this);
    image12.setOnClickListener(this);
    image13.setOnClickListener(this);
    image14.setOnClickListener(this);
    image15.setOnClickListener(this);
    image16.setOnClickListener(this);
    image17.setOnClickListener(this);
    image18.setOnClickListener(this);
    image19.setOnClickListener(this);
public void onClick(android.view.View v) {


switch (v.getId()){

case R.id.IVimage1:
    display.setImageResource(R.drawable.a1);
break;

case R.id.IVimage2:
    display.setImageResource(R.drawable.a2);
    break;
case R.id.IVimage3:
    display.setImageResource(R.drawable.a3);
    break;
case R.id.IVimage4:
    display.setImageResource(R.drawable.a4);
    break;
case R.id.IVimage5:
    display.setImageResource(R.drawable.a5);
break;
case R.id.IVimage6:
    display.setImageResource(R.drawable.a6);
    break;
case R.id.IVimage7:
    display.setImageResource(R.drawable.a7);
    break;
case R.id.IVimage8:
    display.setImageResource(R.drawable.a8);
    break;

    }
}
}

1 个答案:

答案 0 :(得分:0)

您可以执行类似

的操作
TextView desc = (TextView)findViewById(R.id.Aciklama);
desc.setText(DESCRIPTION);

您完全按照显示图像视图执行的操作。单击时创建对textview和setText的引用。