标签: android-layout

如何删除Android上ListViews之间的行?

我正在使用两个ListView这样的:

<ListView
   android:id="@+id/ListView"
   android:text="@string/Website"
   android:layout_height="30px"
   android:layout_width="150px"
   android:scrollbars="none"
   android:transcriptMode="normal"/>
<ListView
   android:id="@+id/ListView1"
   android:text="@string/Website"
   android:layout_height="30px"
   android:layout_width="150px"
   android:scrollbars="none"
   android:transcriptMode="normal"/>
Run Code Online (Sandbox Code Playgroud)

两者之间有一条空白行ListView.我该如何删除它?

android listview android-layout

384
推荐指数
11
解决办法
18万
查看次数

listView项目Android之间的间距

我尝试在listView上使用marginBottom来在listView Item之间创建空格,但仍然将这些项连接在一起.

它甚至可能吗?如果是,是否有特定的方法来做到这一点?

我的代码如下

<LinearLayout
android:id="@+id/alarm_occurences"
android:layout_width="fill_parent" 
android:orientation="vertical"
android:layout_height="fill_parent"
android:background="#EEEEFF"
xmlns:android="http://schemas.android.com/apk/res/android">

<ListView
android:id="@+id/occurences"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

我的自定义列表项:

<com.android.alarm.listItems.AlarmListItem
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" 
android:background="@drawable/alarm_item_background"
android:layout_marginBottom="10dp"    
>
<CheckedTextView     
    android:id="@android:id/text1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center_vertical"
    android:checkMark="?android:attr/listChoiceIndicatorMultiple"
    android:textSize="20sp"
    android:textStyle="bold"
    android:typeface="serif"
    android:padding="10dp"

/>

</com.android.alarm.listItems.AlarmListItem>
Run Code Online (Sandbox Code Playgroud)

在这种情况下,如何在列表项之间建立间距?

android android-layout android-listview

363
推荐指数
9
解决办法
21万
查看次数

LinearLayout不在ScrollView内扩展

我有一个LinearLayout里面ScrollViewandroid:layout_height="fill_parent",但它并没有扩展到的最大高度ScrollView.我的布局看起来像:

level    layout    layout_width    layout_height
1    LinearLayout    fill_parent    fill_parent
2    LinearLayout    fill_parent    wrap_content
3    (some irrelevant stuff)
2    ScrollView      fill_parent    fill_parent <-- this expands full height
3    LinearLayout    fill_parent    fill_parent <-- this does not (has orientation=vertical)
(following stuff probably are irrelevant, but just to be sure:)
4    TextView        fill_parent    fill_parent
4    LinearLayout    fill_parent    wrap_content
Run Code Online (Sandbox Code Playgroud)

我可以看到LinearLayout它没有扩展整个高度,ScrollView因为在Eclipse中Android Layout Editor,如果我选择ScrollView(在"大纲"面板中)它会突出显示一个红色边框,将屏幕填充到底部但是当我选择LinearLayout它的高亮显示时不会扩展到屏幕的底部.我怎么能这样做?

我想要达到的效果是在它下面有一些文字和一个按钮(在第LinearLayout4级里面只有一个按钮).文本可能足够大,需要滚动条,在这种情况下,我希望用户必须向下滚动才能看到按钮.如果文本不够大,滚动条,我希望LinearLayout包含按钮粘在屏幕的底部. …

android android-layout

362
推荐指数
4
解决办法
14万
查看次数

android:drawableLeft边距和/或填充

是否可以为我们添加的图像设置边距或填充android:drawableLeft

android android-layout android-drawable

354
推荐指数
14
解决办法
22万
查看次数

Android工具栏中心标题和自定义字体

我正在尝试找出使用自定义字体作为工具栏标题的正确方法,并将其置于工具栏中(客户端要求).

目前,我正在使用旧的ActionBar,我将标题设置为空值,并使用setCustomView自定义字体TextView并使用ActionBar.LayoutParams将其居中.

有没有更好的方法呢?使用新工具栏作为我的ActionBar.

android android-layout android-theme android-styles android-toolbar

347
推荐指数
16
解决办法
34万
查看次数

如何以编程方式设置layout_gravity?

我的问题很简单,

如何以编程方式设置我的按钮layout_gravity?

我在互联网上发现了这个,但它只是抛出了一个Nullpointer异常:

 Button MyButton = new Button(this);

    LinearLayout.LayoutParams  lllp=(LinearLayout.LayoutParams)MyButton.getLayoutParams();
    lllp.gravity=Gravity.RIGHT;
    MyButton.setLayoutParams(lllp); 


    MyLinearLayout.addView(MyButton);
Run Code Online (Sandbox Code Playgroud)

有解决方案吗

android android-layout

309
推荐指数
11
解决办法
26万
查看次数

调用setCompoundDrawables()不会显示Compound Drawable

调用setCompoundDrawables方法后,未显示复合Drawable ..

Drawable myDrawable = getResources().getDrawable(R.drawable.btn);
btn.setCompoundDrawables(myDrawable, null, null, null);
Run Code Online (Sandbox Code Playgroud)

有什么想法吗?

android android-layout android-drawable

305
推荐指数
7
解决办法
7万
查看次数

如何使用RecyclerView构建Horizo​​ntal ListView?

我需要在我的Android应用程序中实现水平列表视图.我做了一些研究并遇到了如何在Android中制作水平ListView?Android中的水平ListView?然而,这些问题是在Recyclerview发布之前提出的.现在使用Recyclerview有更好的方法来实现吗?

android android-layout android-recyclerview

305
推荐指数
8
解决办法
27万
查看次数

使用appcompat v7更改EditText底线颜色

我正在使用appcompat v7来获得Android 5及更低版本的外观.它工作得很好.但是我无法弄清楚如何更改EditTexts的底线颜色和重点颜色.可能吗?

我试图定义一个自定义android:editTextStyle(参见下面),但我只是成功地改变了整个背景颜色或文本颜色,但没有改变底线和强调颜色.是否有特定的财产价值?我是否必须通过该android:background属性使用自定义可绘制图像?是不是可以用hexa指定颜色?

 <style name="Theme.App.Base" parent="Theme.AppCompat.Light.DarkActionBar">
     <item name="android:editTextStyle">@style/Widget.App.EditText</item>
 </style>

 <style name="Widget.App.EditText" parent="Widget.AppCompat.EditText">
     ???
 </style>
Run Code Online (Sandbox Code Playgroud)

根据android API 21的消息来源,EditTexts与材料设计似乎使用colorControlActivatedcolorControlNormal.因此,我试图在先前的样式定义中覆盖这些属性,但它没有任何效果.可能appcompat不使用它.不幸的是,我找不到上一版appcompat的材料设计来源.

java android android-layout android-edittext android-styles

303
推荐指数
18
解决办法
30万
查看次数

Android布局中的<merge>标签的目的是什么?

我在标签上看过Romain Guy的帖子<merge />,但我仍然不明白它是如何有用的.它是<Frame />标签的一种替代品,还是像这样使用:

<merge xmlns:android="....">
<LinearLayout ...>
    .
    .
    .
</LinearLayout>
</merge>
Run Code Online (Sandbox Code Playgroud)

那么<include />代码在另一个文件中?

code-reuse android include android-layout

299
推荐指数
5
解决办法
11万
查看次数