这是关于Android中ListView中项目布局的一个非常好的问题.
我有一个活动,顶部有一个标题栏,ListView占据了屏幕的其余部分.我希望我的ListView在左侧,右侧和顶部显示10dp填充,但是当您向上滚动ListView时,我希望它覆盖顶部10dp填充,然后在褪色边缘消失.同样,当你滚动到底部时,最后一个列表项应该在最后一个列表项的底部和屏幕的实际底部之间显示为10dp(如果你想知道为什么,那是因为我想要一个漂亮的背景图像在ListView周围探索).
我已经尝试将填充添加到ListView本身,但是当您滚动列表时它会在填充的边缘消失.
我来自web开发背景,类比是在第一个列表项(和最后一个列表项下方)之上添加边距.
我想知道,如果我只提供单层LinearLayout
ListView的行视图,它的边距将被忽略.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
Run Code Online (Sandbox Code Playgroud)
但是,如果我提供双层LinearLayout
,第一层充当"虚拟"层,其边距将不会被忽略.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/buyPortfolioLinearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
Run Code Online (Sandbox Code Playgroud)
我可以知道为什么会这样吗?
设置时
android:clipToPadding="false"
Run Code Online (Sandbox Code Playgroud)
在2.3.3安卓设备上的标准ListView中,我看到列表项目过早被回收.适配器的视图在完全滚动到填充之后被移除而不是滚动超过屏幕边缘导致视图被过早删除.有没有人能够解决这个问题?
目前在Android 4.3设备上.我正在使用这里提供的优秀答案我能够减少AlertDialog
单个项目的字体大小:
<style name="AlertDialogTheme" parent="android:Theme.Dialog">
<item name="android:textSize">13sp</item>
</style>
Run Code Online (Sandbox Code Playgroud)
对话框本身构建为:
ContextThemeWrapper cw = new ContextThemeWrapper( this, R.style.AlertDialogTheme );
AlertDialog.Builder builder = new AlertDialog.Builder(cw);
Run Code Online (Sandbox Code Playgroud)
但是,问题是项目的个别高度仍然保持不变 - 实际上,当您在对话框中滚动时,会显示第五个元素:
我尝试设置dividerHeight
但只是增加了间距.我也把layout_margin
财产设置为0dp
没有成功.
此对话框的正确样式定义是什么,以减少标签之间的空间?
请注意,我不想再使用视图构建整个对话框.我想保留现有的AlertDialog.
我遇到了以下问题:我有一个ListView,我从xml文件中获取其项目的布局.但事情是,顺序项之间应该有一些空间,我通过将布局嵌套到虚拟RelativeLayout中来完成,这样我就可以将marginTop =""设置为包含项目的布局.问题是当用户单击ListView的项目时,整个区域(包括顺序项之间的间隙)变为选中状态.我该如何处理?谢谢!