-1

大家好!!我已经在gridview中显示了图像。现在单击gridview中的任何图像时,我将导航到下一页,单击的图像显示在屏幕上。根据我的需要,我必须在全屏上添加图像的描述我已经采取了 TextView 但它没有发生。这是我的代码......

全图.java

public class FullImage extends Activity {
private TextView lView = null;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.full);

    // get intent data
    Intent i = getIntent();

    // Selected image id
    int position = i.getExtras().getInt("id");

    if (position == 1){
        lView = (TextView)findViewById(R.id.my_title);
        lView.setText("Akshardham");

    }
    else{
        lView = (TextView)findViewById(R.id.my_title);
        lView.setText("Other");

    }



    ImageAdapter imageAdapter = new ImageAdapter(this);

    ImageView imageView = (ImageView) findViewById(R.id.full_image_view);
    imageView.setImageResource(imageAdapter.mThumbIds[position]);
}

和 Full.xml

<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/full_image_view"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"/>

<TextView
android:id="@+id/my_title"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="5dip"/>

这是我的主要活动类代码..

gridView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View v,
                int position, long id) {

            // Sending image id to FullScreenActivity
            Intent i = new Intent(getApplicationContext(), FullImage.class);
            // passing array index
            i.putExtra("id", position);
            startActivity(i);
        }
    });
}

这是我的 ImageAdapter 代码...

public class ImageAdapter extends BaseAdapter {
private Context mContext;

// Keep all Images in array
public Integer[] mThumbIds = {
        R.drawable.akshar, R.drawable.charminar,
        R.drawable.gateway, R.drawable.goa,
        R.drawable.jimcorbet, R.drawable.kerala,
        R.drawable.mussoorie, R.drawable.parliament,
        R.drawable.qutub, R.drawable.taj,
        R.drawable.tirupati

};

// Constructor
public ImageAdapter(Context c){
    mContext = c;
}

@Override
public int getCount() {
    return mThumbIds.length;
}

@Override
public Object getItem(int position) {
    return mThumbIds[position];
}

@Override
public long getItemId(int position) {
    return 0;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    ImageView imageView = new ImageView(mContext);
    imageView.setImageResource(mThumbIds[position]);
    imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
    imageView.setLayoutParams(new GridView.LayoutParams(270, 270));
    return imageView;
}

}

4

1 回答 1

1

这里 imageView 是高度和宽度的填充父级,因此它占用了屏幕上的所有可用空间。所以你需要设计你的布局,以便按顺序显示两个元素。

<RelativeLayout
    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/full_image_view"
        android:layout_width="fill_parent"
        android:src="@drawable/button"
        android:layout_height="wrap_content" />

    <TextView
        android:id="@+id/my_title"
        android:layout_centerHorizontal="true"
        android:layout_below="@+id/full_image_view"
        android:layout_height="wrap_content"
        android:text="This is the image which i want at bottom"
        android:layout_width="wrap_content"
        android:layout_marginLeft="5dip" />
</RelativeLayout>
于 2013-03-12T05:03:20.463 回答