开发者

How can i put text under each imagaview

开发者 https://www.devze.com 2023-04-09 07:00 出处:网络
In my project i am using images as button in horizontalscrollview. When i click an image it shows the image above the horizantalscrollview. What i want is to show a description text under the image wh

In my project i am using images as button in horizontalscrollview. When i click an image it shows the image above the horizantalscrollview. What i want is to show a description text under the image when i click it. Can anyhone help?

Here is my xml file.

<?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:l开发者_如何转开发ayout_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>

Here is my java file.

    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;

    }
}
}


You can do something like

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

You do exactly what you did with the display imageview. Create a reference to the textview and setText to it on click.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号