2

Android のギャラリーの設定サイズに問題があります。ギャラリーのサイズを設定したい (デバイスの画面の半分など) 私はこのコードを使用しています:

int width = (int) getResources().getDimension(R.dimen.image_height);
int height = (int) getResources().getDimension(R.dimen.image_width);
iv.setLayoutParams(new Gallery.LayoutParams(width, height));
iv.setLayoutParams(new Gallery.LayoutParams(30, 40)); `

および main.xml:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
    <TextView
        android:id="@+id/mySelection"
        android:layout_width="fill_parent"
        android:layout_height="
        android:background="#ffffff"
        android:textSize="20px"
        android:textStyle="bold" />

    <Gallery
        android:id="@+id/myGallery"
        android:layout_width="fill_parent"
        android:layout_height="30dp"
        android:gravity="bottom" 
         android:spacing="
    <ListView
        android:id="@+id/listView1"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:layout_weight="0.46" />
</LinearLayout>` 

images.xmlまた、ファイルに深さと高さを設定しても機能しません。

4

1 に答える 1

0

urの高さが機能していません。cozuは値を指定しませんでした。urのコードをもう一度参照してください。gridviewのサイズを設定するには、次のコードを使用します。

Display display = activity.getWindowManager().getDefaultDisplay();
    int halfDeviceWidth = display.getWidth()/2;
    int halfDeviceHeight = display.getHeight()/2;
iv.setLayoutParams(new Gallery.LayoutParams(halfDeviceWidth, halfDeviceHeight));

このコードを使用してください。

于 2012-10-08T10:39:15.203 に答える