尝试制作布局库时,文本显示为暗淡(最初)
我正在尝试制作一个功能类似于 Android 市场的画廊,您可以在其中滚动(左/右)以查看免费或付费应用程序等...还可以在布局中上下滚动。
到目前为止,我只是加载了两个布局,其中有一个简单的“Hello World!”文本视图和“嘿!你好吗?”文本视图。
它们加载得很好,除了最初画廊位置 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 在这个线程中所做的正是我想要达到的目的...
线程链接: 获取按钮以在具有膨胀布局的画廊中工作
有任何帮助吗?
提前致谢。
I am trying to make a gallery that functions similar to the android market where you can scroll (left/right) to view free or paid apps and etc... Also be able to scroll up and down through a layout.
So far I just have it loading two layouts that have a simple "Hello World!" text view and a "Hey! how are you?" text view.
They load fine, except initially the text at position 0 of the gallery shows up dim until I scroll away and back to it. Is there something that I'm missing?
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;
}
}
I also referenced this a little bit. What Aavon in this thread is doing is exactly what I'm trying to get at...
Thread Link: Get button to work in gallery with inflated layouts
Any help?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在我的布局 xml 中,我发现我没有设置屏幕上显示的文本的颜色。当我设置该颜色时,加载布局时文本不再变暗。
In my layout xml, I found that I wasn't setting the color for the text that was appearing on the screen. When I set that color, the text no longer dims out when loading the layout.