我有一个水平的文字列表视图。我想在这些文本之间添加COLORED BULLET POINTS。我使用Gallery来显示水平列表视图。最终视图应与图像中的相同。另外,如何在Gallery和textview之间的图像中获得分隔符?
Activity
public class MainActivity extends Activity {
Gallery myHorizontalListView;
MyAdapter myAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myHorizontalListView = (Gallery)findViewById(R.id.horizontallistview);
myAdapter = new MyAdapter(this);
myHorizontalListView.setAdapter(myAdapter);
myHorizontalListView.setOnItemClickListener(new OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
Toast.makeText(MainActivity.this, parent.getItemAtPosition(position).toString() + " Clicked", Toast.LENGTH_LONG).show();
}});
}
public class MyAdapter extends BaseAdapter {
Context context;
String[] itemsArray = {
"SUN","MON", "TUS", "WED", "THU", "FRI", "SAT"};
MyAdapter(Context c){
context = c;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return itemsArray.length;
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return itemsArray[position];
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View rowView = LayoutInflater
.from(parent.getContext())
.inflate(R.layout.row, null);
TextView listTextView = (TextView)rowView.findViewById(R.id.itemtext);
listTextView.setText(itemsArray[position]);
return rowView;
}
}
}
答案 0 :(得分:1)
使用drawableLeft
属性在textview中添加项目符号
至于xml
android:drawableLeft="your_file"
同样在你的视图中第一张图片没有子弹然后在代码中检查
if(position == 0)
listTextView.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);