0

このフォーラムを上下に検索して、さまざまな解決策を見つけましたが、どれも期待どおりに機能しませんでした。私は、オープンソースであり、私がここで達成しようとしていることにあまりにも複雑に思えた Shelves プロジェクトを調べてみました。

本棚/本棚の背景を持つ画面があり、以下のコードで必要に応じてスクロールします。私の RelativeLayout の高さは尊重されていないようで、100dp から 200dp に変更しても違いはありません。基本的に、GridView の各行を正確に同じ高さにし、サムネイル画像の下部を垂直方向に揃えて、画像が本棚に配置されるようにする必要があります。ImageView自体のレイアウトの幅/高さをハードコーディングすることで、これを達成しました。何が起こっているかを確認できるように背景色を使用してみましたが、それでも一貫した外観を実現できません。また、画像を一貫したサイズに縮小しようとしています。たとえば、画像の形状が異なる場合でも、100x100 としましょう (一部は正方形で、一部は長方形です)。私もできる」

誰が私が間違っているのか教えてもらえますか? 私が思いついたのは完全なハックかもしれませんが、私は近いと思います:-/

これは、デバッグ/テストの目的で青色の背景色を使用して、現在作業しているスクリーンショットへのリンクです。

本棚のスクリーンショット

/res/layout/titles.xml

<com.alex.android.view.BookShelfView 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/my_titles_grid_view"
    android:cacheColorHint="@android:color/transparent"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:numColumns="auto_fit"
    android:stretchMode="columnWidth"
    android:verticalSpacing="25dp"
    android:gravity="bottom"/>

ImageAdapter 

class ImageAdapter extends BaseAdapter {
    private Context mContext;
    public ImageAdapter(Context c) {
        mContext = c;
    }

    public int getCount() {
        return borrowedAssets.size();
    }

    public Object getItem(int position) {
        return borrowedAssets.get(position);
    }

    public long getItemId(int position) {
        return borrowedAssets.get(position).getContentId();
    }

    // create a new ImageView for each item referenced by the Adapter
    public View getView(int position, View convertView, ViewGroup parent) {

        View cellView;

        if (convertView == null) {  // if it's not recycled, initialize some attributes
            cellView = getLayoutInflater().inflate(R.layout.title_cell, null);
            ImageView image = (ImageView) cellView.findViewById(R.id.title_thumbnail);
            new DownloadImageTask(image).execute(getString(R.string.thumbnails_server_url)+borrowedAssets.get(position).getThumbnail());
        } else {
            cellView = convertView;
        }

        return cellView;
    }
}

/res/layout/title_cell.xml


<RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="100dp"
        android:layout_height="100dp">

    <ImageView android:id="@+id/title_thumbnail"
            android:layout_width="100dp"
            android:layout_height="140dp"
            android:paddingTop="25dp"
            android:scaleType="fitStart"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            android:background="@color/blue_color"
            android:contentDescription="thumbnail"/>

</RelativeLayout>
4

1 に答える 1

0

私の RelativeLayout の高さは尊重されていないようで、100dp から 200dp に変更しても違いはありません

カスタム アダプターではparent、次のように inflate メソッドでパラメーターを使用します。

cellView = getLayoutInflater().inflate(R.layout.title_cell, parent, false);

また、現在のgetView方法では、リサイクルされた( )がない場合にImageView のみイメージを設定するため、リサイクルされた場合は同じイメージになることに注意してください。ViewconvertView == nullView

于 2012-06-30T14:50:12.147 に答える