Tag: android layout

Android Lint contentDescription警告

我得到警告作为“[可访问性] imageview丢失imageDescription属性”。 同时使用android lint 那是什么意思?

Android应用程序中TextView的字体大小会根据本地设置更改字体大小而发生变化

我想在我的应用程序中指定自己的文本大小,但是我遇到了一个问题。 当我在设备设置中更改字体大小时,我的应用程序TextView的字体大小也会改变。

Android TableLayout中“colspan”的等价物是什么?

我在Android中使用TableLayout。 现在我有一个TableRow,其中有两个项目,在它下面有一个TableRow。 它呈现如下: —————————– | Cell 1 | Cell 2 | —————————– | Cell 3 | ————— 我想要做的是让Cell 3在两个上层单元之间伸展,所以它看起来像这样: —————————– | Cell 1 | Cell 2 | —————————– | Cell 3 | —————————– 在HTML中,我会使用COLSPAN ….我如何使这项工作在Android?

ellipsize在android中意味着什么?

我已经添加了一个EditText到我的布局,并添加了一个提示,并使其水平居中。 运行应用程序时,提示是不可见的。 我发现我应该使TextView ellipsize值start : <EditText android:id="@+id/number1EditText" android:layout_width="match_parent" android:layout_height="wrap_content" android:ellipsize="start" android:ems="10" android:gravity="center_horizontal" android:hint="@string/hint1" /> 在Android文档中,我读到: 如果设置,导致比视图更长的单词是广泛的 椭圆化,而不是在中间破碎。 问题是在字典中找不到ellipsize 。 有人可以向我解释我们可以通过ellipsize属性获得什么好处吗? start , end , middle什么区别?

如何使视图填充剩余的空间?

我正在devise我的应用程序UI。 我需要一个布局如下所示: (<和>是button)。 问题是,我不知道如何确保TextView将填充剩余的空间,用两个button有固定的大小。 如果我为文本视图使用fill_parent,则不能显示第二个button(>)。 我如何制作一个看起来像图像的布局?

RecyclerView:检测到不一致。 无效的项目位置

我们的QA发现了一个bug:在Android设备(Droid Turbo)旋转时,发生了以下与RecyclerView相关的崩溃: java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid item position 2(offset:2).state:3 对我来说,它看起来像RecyclerView内部的错误,因为我不能想到这是由我们的代码直接造成的任何方式… 有没有人遇到过这个问题? 什么是解决scheme? 一个残酷的解决方法可能是在发生exception时捕获exception,并从头开始重新创buildRecyclverView实例,以避免出现损坏状态。 但是,如果可能的话,我想更好地理解这个问题(也许可以从源头上解决问题),而不是掩盖它。 该错误不容易重现,但发生时是致命的。 完整的堆栈跟踪: >W/dalvikvm( 7546): threadid=1: thread exiting with uncaught exception (group=0x41987d40) >E/AndroidRuntime( 7546): FATAL EXCEPTION: main >E/AndroidRuntime( 7546): Process: com.oblong.mezzedroid, PID: 7546 >E/AndroidRuntime( 7546): java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid item position 2(offset:2).state:3 >E/AndroidRuntime( 7546): at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:3382) >E/AndroidRuntime( 7546): at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:3340) >E/AndroidRuntime( 7546): […]

在Android中,在顶部ListView项目(和最后一个)之上添加保证金

这是关于Android中的ListView中的项目布局的一个很好的问题。 我有一个顶部的标题栏和一个ListView的活动占据屏幕的其余部分。 我希望我的ListView在左侧,右侧和顶部显示为10dp填充,但是当您向上滚动ListView时,我希望它覆盖顶部10dp填充,然后消失在褪色边缘下方。 同样,当您滚动到底部时,最后一个列表项应该在最后一个列表项的底部和屏幕的实际底部之间显示10dp(如果您想知道原因,那是因为我想要一个漂亮的背景图像在ListView周围拨出)。 我已经尝试添加填充ListView本身,但随后当您滚动列表它消失在边缘的填充。 我来自一个web开发背景,类比将是在第一个列表项目(和最后一个列表项目之下)之上添加保证金。

styles.xml中的自定义属性

我创build了一个自定义小部件,并在layout.xml中声明它。 我还在attr.xml中添加了一些自定义属性。 但是,当试图在styles.xml中声明这些属性时,它会给我No resource found that matches the given name: attr 'custom:attribute'. 我已经在styles.xml中的所有标记中放入了xmlns:custom="http://schemas.android.com/apk/res/com.my.package" ,包括<?xml> , <resources>和<style> ,但它仍然给我同样的错误,它找不到我自定义的XML名称空间。 但是,我可以使用我的命名空间在layout.xml中为视图手动分配属性,所以名称空间没有任何问题。 我的问题在于使styles.xml知道我的attr.xml。

Android:如何绘制一个LinearLayout的边框

我有三个文件。 XML,绘图function和主要活动。 我在我的XML文件中有一些LinearLayout 。 <LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1"> <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:background="#ef3" android:id="@+id/img01"/> <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:background="#E8A2B4" android:id="@+id/img02"/> </LinearLayout> 这是绘图function: public class getBorder extends TextView { public getBorder(Context context) { super(context); } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); Paint paint = new Paint(); paint.setColor(android.graphics.Color.RED); canvas.drawLine(0, 0, this.getWidth() – 1, 0, paint); […]

具有两列的Gridview和自动resize的图像

我正在试图使两列的网格视图。 我的意思是每行两张照片并排,就像这张照片一样。 但我的照片之间有空间,因为它的大小不一样。 这是我得到的。 您可以看到第一张图片隐藏了显示联系人姓名和电话号码的图例。 而其他图片没有正确拉伸。 这是我的GridView XML文件。 正如你所看到的columnWidth设置为200dp 。 我希望它是自动的 ,所以图片将自动调整为每个屏幕大小。 <?xml version="1.0" encoding="utf-8"?> <GridView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/gridViewContacts" android:layout_width="fill_parent" android:layout_height="fill_parent" android:numColumns="2" android:columnWidth="200dp" android:stretchMode="columnWidth" android:gravity="center" /> 这里是项目xml文件,它代表每个项目本身。 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <ImageView android:id="@+id/imageViewContactIcon" android:layout_width="match_parent" android:layout_height="match_parent" android:scaleType="fitXY" /> <LinearLayout android:id="@+id/linearlayoutContactName" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:paddingLeft="5dp" android:paddingTop="5dp" android:paddingBottom="5dp" android:background="#99000000" android:layout_alignBottom="@+id/imageViewContactIcon"> <TextView android:id="@+id/textViewContactName" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#FFFFFF" […]