0

小さな画面 (2.7 インチ) 用のグリッドビューでレイアウトを作成しました。私のアイコンは 48 x 48 ピクセルです。今、タブレットにグリッドビューが必要なので、新しいレイアウトを作成し、設定を大きくて横向きに変更しました。タブレット用により大きなアイコン (72 x 72 ピクセル) を使用したい。問題は、大きいアイコンは表示されず、小さいアイコンは表示されることです。私の小さなアイコンはフォルダー drawable-mdpi にあり、大きなアイコンはフォルダー drawable-hdpi にあります。大きなアイコンをdrawable-xhdpiフォルダーに移動しようとしましたが、成功しませんでした。imageadapter の scaletype と layoutparams も変更しようとしましたが、成功しませんでした。

大きなレイアウトの私のコードは次のとおりです。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/back" >



<GridView
    android:id="@+id/Menu"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_below="@+id/imageView1"
    android:columnWidth="80dp"
    android:gravity="center_horizontal|top"
    android:horizontalSpacing="130dp"
    android:numColumns="auto_fit"
    android:paddingTop="10dp"
    android:scrollbars="none"
    android:stretchMode="columnWidth"
    android:verticalSpacing="50dp" android:layout_marginTop="50dip">

</GridView>

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:src="@drawable/title" />

</RelativeLayout>

グリッドビュー用の私のイメージアダプターの Java コードは次のとおりです。

public class ImageAdapter extends BaseAdapter 
{
    private Context context;

    public ImageAdapter(Context c) 
    {
        context = c;
    }

    //---returns the number of images---
    public int getCount() {
        return menu_icon.length;
    }

    //---returns the ID of an item--- 
    public Object getItem(int position) {
        return null;
    }

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

    //---returns an ImageView view---
    public View getView(int position, View convertView, ViewGroup parent) 
    {
        ImageView imageView;
        if (convertView == null) {
            imageView = new ImageView(context);
            imageView.setLayoutParams(new GridView.LayoutParams(150, 150));                 imageView.setScaleType(ImageView.ScaleType.CENTER);
            imageView.setPadding(5, 5, 5, 5);
        } else {
            imageView = (ImageView) convertView;
        }
        imageView.setImageResource(menu_icon[position]);
        return imageView;


    }
}
4

2 に答える 2

0

これを試して、

imageView.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT); 

これはうまくいくかもしれません。

于 2012-06-27T09:08:58.840 に答える