是否有可能使ListView水平?我使用图库视图完成了此操作,但所选项目会自动出现在屏幕的中心。我不希望选中的项目位于我点击的同一位置。我该如何纠正这个问题?我的想法是用水平滚动来设置ListView。分享你的想法?
当前回答
其实很简单: 简单地旋转列表视图躺在它的一边
mlistView.setRotation(-90);
然后在膨胀子对象时,它应该在getView方法中。你让孩子们站直:
mylistViewchild.setRotation(90);
编辑: 如果你的ListView在旋转后不合适,把ListView放在这个RotateLayout中,就像这样:
<com.github.rongi.rotate_layout.layout.RotateLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:angle="90"> <!-- Specify rotate angle here -->
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent">
</ListView>
</com.github.rongi.rotate_layout.layout.RotateLayout>
其他回答
Paul没有费心去修复他的库中的bug或接受用户的修复。这就是为什么我建议另一个具有类似功能的库:
https://github.com/sephiroth74/HorizontalVariableListView
更新:2013年7月24日作者(sephiroth74)发布了基于android 4.2.2 ListView代码的完全重写版本。我必须说,它没有所有的错误,以前的版本有和伟大的工作!
你可以使用ViewFlipper来包含布局XML,并为每个布局XML添加图像、列表视图
为了找到解决这个问题的办法,我做了很多研究。简短的回答是,没有好的解决方案,除非重写私有方法之类的东西。我发现最好的方法是自己从头开始通过扩展AdapterView来实现它。这很悲惨。请看我关于水平listview的SO问题。
你总是可以创建你的textviews等动态和设置你的onclicklistener,就像你会做一个适配器
从这里下载jar文件
现在把它放到你的libs文件夹中,右键点击它并选择“添加为库”
现在在main.xml中放入这段代码
<com.devsmart.android.ui.HorizontalListView
android:id="@+id/hlistview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
现在在Activity类中,如果你想要带有图像的水平列表视图,那么就把这段代码放进去
HorizontalListView hListView = (HorizontalListView) findViewById(R.id.hlistview);
hListView.setAdapter(new HAdapter(this));
private class HAdapter extends BaseAdapter {
LayoutInflater inflater;
public HAdapter(Context context) {
inflater = LayoutInflater.from(context);
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return Const.template.length;
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
HViewHolder holder;
if (convertView == null) {
convertView = inflater.inflate(R.layout.listinflate, null);
holder = new HViewHolder();
convertView.setTag(holder);
} else {
holder = (HViewHolder) convertView.getTag();
}
holder.img = (ImageView) convertView.findViewById(R.id.image);
holder.img.setImageResource(Const.template[position]);
return convertView;
}
}
class HViewHolder {
ImageView img;
}
推荐文章
- 警告:API ' variable . getjavacompile()'已过时,已被' variable . getjavacompileprovider()'取代
- 安装APK时出现错误
- 碎片中的onCreateOptionsMenu
- TextView粗体通过XML文件?
- 如何使线性布局的孩子之间的空间?
- DSL元素android.dataBinding。enabled'已过时,已被'android.buildFeatures.dataBinding'取代
- ConstraintLayout:以编程方式更改约束
- PANIC: AVD系统路径损坏。检查ANDROID_SDK_ROOT值
- 如何生成字符串类型的buildConfigField
- Recyclerview不调用onCreateViewHolder
- Android API 21工具栏填充
- Android L中不支持操作栏导航模式
- 如何在TextView中添加一个子弹符号?
- PreferenceManager getDefaultSharedPreferences在Android Q中已弃用
- 在Android Studio中创建aar文件