Tag: android layout

嵌套的Recycler视图高度不包裹其内容

我有一个pipe理书籍(如播放列表)的应用程序。 我想要显示一个垂直RecyclerView的集合列表,并在每行内部显示一个水平RecyclerView的书籍列表。 当我将内部水平RecyclerView的layout_height设置为300dp时,它显示正确,但是当我将其设置为wrap_content时,它不显示任何内容。 我需要使用wrap_content,因为我希望能够以编程方式更改布局pipe理器以在垂直和水平显示之间切换。 你知道我在做什么错吗? 我的片段布局: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/white"> <com.twibit.ui.view.CustomSwipeToRefreshLayout android:id="@+id/swipe_container" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <android.support.v7.widget.RecyclerView android:id="@+id/shelf_collection_listview" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingTop="10dp"/> </LinearLayout> </com.twibit.ui.view.CustomSwipeToRefreshLayout> </LinearLayout> 集合元素布局: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#FFF"> <!– Simple Header –> </RelativeLayout> <FrameLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <TextView android:layout_width="match_parent" android:layout_height="match_parent" android:text="@string/empty_collection" android:id="@+id/empty_collection_tv" android:visibility="gone" android:gravity="center"/> <android.support.v7.widget.RecyclerView android:id="@+id/collection_book_listview" […]

设置Android布局元素的背景颜色

我试图从Android UIdevise中的一组幻灯片中克隆一个活动的devise 。 但是,我有一个非常简单的任务的问题。 我已经创build了如图所示的布局,并且标题是RelativeLayout的TextView 。 现在我想改变RelativeLayout的背景颜色,但我似乎无法弄清楚如何。 我知道我可以在XML文件的RelativeLayout标签中设置android:background属性,但是我将它设置为? 我想定义一个新的颜色,我可以在多个地方使用。 这是一个drawable或string ? 另外,我希望在Eclipse Android UIdevise器中有一个非常简单的方法来解决这个问题。 目前我有点沮丧,因为这应该是一个活动,最多只需点击几下。 所以任何帮助,非常感激。 🙂

GridLayout(不是GridView)如何均匀拉伸所有的孩子

我想要一个2×2的网格,里面有一个button。 这只是ICS,所以我正在尝试使用新的GridLayout。 这是我的布局的XML: <?xml version="1.0" encoding="utf-8"?> <GridLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/favorites_grid" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#00ff00" android:rowCount="2" android:columnCount="2"> <Button android:text="Cell 0" android:layout_row="0" android:layout_column="0" android:textSize="14dip" /> <Button android:text="Cell 1" android:layout_row="0" android:layout_column="1" android:textSize="14dip" /> <Button android:text="Cell 2" android:layout_row="1" android:layout_column="0" android:textSize="14dip" /> <Button android:text="Cell 3" android:layout_row="1" android:layout_column="1" android:textSize="14dip" /> </GridLayout> 问题是,我的意见不是平均每行拉伸。 这导致了我的GridLayout右边的很多额外的空间。 我试过设置layout_gravity="fill_horizontal"但只适用于行上的最后一个视图。 这意味着单元1一直延伸到为单元0提供足够的空间。 关于如何解决这个问题的思考?

Android的LinearLayout渐变背景

我无法对LinearLayout应用渐变背景。 这应该是相对简单的,因为我已经阅读,但它似乎并没有工作。 有关参考资料,我正在开发2.1-update1。 header_bg.xml: <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <gradient android:angle="90" android:startColor="#FFFF0000" android:endColor="#FF00FF00" android:type="linear"/> </shape> main_header.xml: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="50dip" android:orientation="horizontal" android:background="@drawable/header_bg"> </LinearLayout> 如果我将@ drawable / header_bg更改为一种颜色 – 例如#FF0000,它可以很好地工作。 我在这里错过了很明显的东西吗

如何更改android操作栏的标题和图标

我正在尝试在Android的ActionBar上做一些事情。 我已经在操作栏的右侧添加了新项目。 我如何更改操作栏的左侧? 我想更改图标和文本,我想在其他屏幕的操作栏中添加“后退button”

如何更改textview超链接的颜色?

我正在使用此代码进行超链接: <TextView android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/hyperlink" android:text="@string/hyperlink" android:autoLink="web"/> 默认情况下显示为蓝色,但是如何更改Android中超链接的颜色?

如何以编程方式在RelativeLayout中布局视图?

我试图通过编程实现以下(而不是通过XML声明): <RelativeLayout…> <TextView … android:id="@+id/label1" /> <TextView … android:id="@+id/label2" android:layout_below: "@id/label1" /> </RelativeLayout> 换句话说,如何让第二个TextView出现在第一个TextView下面,但我想在代码中做到这一点: RelativeLayout layout = new RelativeLayout(this); TextView label1 = new TextView(this); TextView label2 = new TextView(this); … layout.addView(label1); layout.addView(label2); setContentView(layout); 更新: 谢谢,TreeUK。 我理解大方向,但仍然不起作用 – “B”重叠“A”。 我究竟做错了什么? RelativeLayout layout = new RelativeLayout(this); TextView tv1 = new TextView(this); tv1.setText("A"); TextView tv2 = new TextView(this); […]

线性布局和Android的重量

我总是阅读Android文档中有趣的重量值。 现在我想第一次尝试它,但它根本不工作。 据我所知,这个布局是: <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <Button android:text="Register" android:id="@+id/register" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="10dip" weight="1" /> <Button android:text="Not this time" android:id="@+id/cancel" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="10dip" weight="1" /> </LinearLayout> 应创build两个水平alignment的button并平均分配空间。 问题是两个button不能长大,以填补空间。 我想button增长和填补整个线路。 如果两个button都设置为与父母匹配,则只显示第一个button并填充整行。

调用setCompoundDrawables()不会显示Compound Drawable

在我调用setCompoundDrawables方法后,复合Drawable不显示.. Drawable myDrawable = getResources().getDrawable(R.drawable.btn); btn.setCompoundDrawables(myDrawable, null, null, null); 有什么想法吗?

android:drawableLeft margin和/或padding

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