1

無料または有料のアプリなどを表示するためにスクロール(左/右)できるAndroidマーケットと同様に機能するギャラリーを作成しようとしています...レイアウトを上下にスクロールすることもできます。

これまでのところ、単純な "Hello World!" を持つ 2 つのレイアウトをロードするだけです。テキスト ビューと「Hey! お元気ですか?」テキストビュー。

それらは問題なく読み込まれますが、最初はギャラリーの位置 0 にあるテキストが薄暗く表示され、スクロールして戻るまで表示されません。私が見逃しているものはありますか?

public class HelloGallery extends Activity
{
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Gallery gallery = (Gallery)findViewById(R.id.gallery);
        gallery.setAdapter(new ViewAdapter(this));

        gallery.setOnItemClickListener(new OnItemClickListener()
        {
            public void onItemClick(AdapterView<?> parent, View v, int position, long id)
            {
                Toast.makeText(HelloGallery.this, "" + position, Toast.LENGTH_SHORT).show();
            }
        });
    }
}


public class ViewAdapter extends BaseAdapter
{
    public Context mContext;
    public static final Integer[] viewId = { R.layout.helloworld, R.layout.heyhowareyou };
    public int mGalleryItemBackground;

    public ViewAdapter(Context context)
    {
        this.mContext = context;
        TypedArray attr = context.obtainStyledAttributes(R.styleable.HelloGallery);
        mGalleryItemBackground = attr.getResourceId(R.styleable.HelloGallery_android_galleryItemBackground, 0);
        attr.recycle();
    }

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

    public Object getItem(int position)
    {
        return position;
    }

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

    @Override
    public View getView(int position, View convertView, ViewGroup parent)
    {
        convertView = LayoutInflater.from(mContext).inflate(viewId[position], null);
        convertView.setLayoutParams(new Gallery.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
        convertView.setBackgroundResource(mGalleryItemBackground);
        return convertView;
    }
}

これも少し参考にしました。このスレッドで Aavon が行っていることは、まさに私が目指していることです...

スレッド リンク:インフレートされたレイアウトのギャラリーで動作するボタンを取得する

何か助けはありますか?
前もって感謝します。

4

1 に答える 1

1

レイアウト xml で、画面に表示されるテキストの色を設定していないことがわかりました。その色を設定すると、レイアウトの読み込み時にテキストが薄暗くならなくなりました。

于 2011-11-08T22:31:46.887 に答える