0

在我的項目中我使用horizo​​ntalscrollview作爲按鈕的圖像。當我點擊圖像時,它顯示horizantalscrollview上方的圖像。我想要的是當我點擊它時在圖像下面顯示一個描述文字。任何人都可以幫忙嗎?我怎樣才能把文本下每個imagaview

這是我的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; 

    } 
} 
} 

回答

0

你可以做這樣的事情

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

你做你與顯示器的ImageView做了什麼。在點擊時創建對textview和setText的引用。

+0

非常感謝!它有幫助。 –

+0

如果這個答案有幫助,請upvote並設置答案。 – blessenm