如何在相对布局中在图像视图上方添加水平1px白线?
<RelativeLayout
android:id="@+id/widget38"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="108px"
android:layout_y="87px"
>
<ImageView
android:id="@+id/widget39"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
>
</ImageView>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud) 我xml在drawable文件夹(circle_status.xml)中有以下内容来创建一个环:
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="ring"
android:innerRadius="15dp"
android:thickness="10dp"
android:useLevel="false">
<solid android:color="#ababf2" />
</shape>
Run Code Online (Sandbox Code Playgroud)
并插入drawable像relativeLayout的背景,如下:
<RelativeLayout
android:id="@+id/RelativeLayout_Status"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="@drawable/circle_status" >
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
问题是,在relativeLayout中出现一个圆而不是一个环.
我使用复数来编译Android应用程序的数量字符串.我完全按照教程中的内容进行操作:
res.getQuantityString(
R.plurals.number_of_comments, commentsCount, commentsCount);
Run Code Online (Sandbox Code Playgroud)
这是复数的定义:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<plurals name="number_of_comments">
<item quantity="zero">No comments</item>
<item quantity="one">One comment</item>
<item quantity="other">%d comments</item>
</plurals>
</resources>
Run Code Online (Sandbox Code Playgroud)
有趣的是,输出字符串与我所定义的一样奇怪:
commentsCount = 0 => "0 comments"
commentsCount = 1 => "One comment"
commentsCount = 2 => "2 comments"
Run Code Online (Sandbox Code Playgroud)
我想这是因为文档说明When the language requires special treatment of the number 0 (as in Arabic).了zero数量.有没有办法强迫我的定义?
我试图在用户填写之后专注于下一个编辑文本.代码工作得很好EditText但是当我应用它时AutoCompleteTextView,键盘中的Next按钮不起作用.光标停留在原处.这是我正在使用的代码:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="11" >
<AutoCompleteTextView
android:id="@+id/etLN"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="3"
android:ems="10"
android:nextFocusDown="@+id/etC"
android:inputType="textPersonName" >
<requestFocus />
</AutoCompleteTextView>
<EditText
android:id="@id/etC"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="4"
android:ems="10"
android:hint="0.0"
android:nextFocusDown="@+id/etD"
android:inputType="numberDecimal"
android:text="" />
<EditText
android:id="@id/etD"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="4"
android:ems="10"
android:nextFocusDown="@+id/etLN2"
android:hint="0.0"
android:inputType="numberDecimal"
android:text="" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
请告诉我这样做的正确方法是什么.谢谢 :)
此问题已解决,请参阅注释以获取详细信息.
我正在扩展现有的Android View并加载一些自定义属性,如使用XML声明自定义Android UI元素和定义自定义attrs中所述.
具有布尔和整数格式的属性可以正常工作,但是当我尝试指定对数组资源的引用时,应用程序在启动时崩溃.我在xml资源文件中定义了一个整数数组,我试图将它用作自定义视图的属性.
我可以使用数组资源来设置android Spinner类的"entries"属性而没有错误,所以它似乎是我的实现中的一个问题.logcat消息似乎没有提供有关崩溃的任何具体信息,但我仍然在寻找,所以如果我找到了什么,我会更新.
属性由(在attrs.xml中)声明:
<declare-styleable name="CustomView">
<attr name="values" format="reference"/>
<attr name="isActive" format="boolean"/>
</declare-styleable>
Run Code Online (Sandbox Code Playgroud)
该数组定义为(在arrays.xml中):
<integer-array name="nums">
<item>1</item>
<item>2</item>
<item>3</item>
</integer-array>
Run Code Online (Sandbox Code Playgroud)
我通过以下方式引用数组:
<com.test.CustomView cv:values="@array/nums" />
Run Code Online (Sandbox Code Playgroud)
这会导致应用程序立即崩溃.此外,如果我引用颜色资源而不是数组,那么应用程序不会崩溃.有人知道如何处理这个问题吗?
如何以编程方式更改#000000图层列表中形状的颜色()?
这是我的图层列表:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="#000000" /> // CHANGE THIS COLOR
</shape>
</item>
<item android:left="5dp">
<shape android:shape="rectangle">
<solid android:color="@color/bg" />
</shape>
</item>
</layer-list>
Run Code Online (Sandbox Code Playgroud) android android-layout android-xml android-fragments android-activity
请考虑以下示例:
<LinearLayout>
<EditText />
<Button />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
并在清单文件中:
android:windowSoftInputMode="adjustPan"
Run Code Online (Sandbox Code Playgroud)
onfocus edittext,软键盘覆盖如下按钮:

但我喜欢这样:

如何滚动视图以使按钮可见?
我什么android:elevation时候使用app:elevation?何时使用?
这两者有什么区别?
android android-layout android-xml android-5.0-lollipop android-5.1.1-lollipop
我已经从Google IO Schedule应用程序源(https://github.com/google/iosched)复制了一个文件
selected_navdrawer_item_background.xml
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/backgroundColor">
<shape>
<solid android:color="#12000000" />
</shape>
</item>
<item android:drawable="?android:selectableItemBackground"/>
</layer-list>
Run Code Online (Sandbox Code Playgroud)
我想用它来突出显示NavigationDrawer中当前选定的项目.我的问题是,当我启动我的应用程序时,它会引发异常.
这是我认为的重要路线.
caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #22:
<item> tag requires a 'drawable' attribute or child tag defining a drawable
Run Code Online (Sandbox Code Playgroud)
第22行是这一行
<item android:drawable="?android:selectableItemBackground"/>
Run Code Online (Sandbox Code Playgroud)
我不知道问题是什么,我从源头复制了它而没有调整它.它在他们的应用程序中运行良好.
我试图改变?android:selectableItemBackground到?attr/selectableItemBackground,但它给了我同样的异常.我似乎无法找到任何其他建议的解决方案.
如果有人知道是什么导致了这一点,请帮助我.
我4年来一直在使用AS.在上次更新后,我观察到了XML布局的意外自动格式化(在键入时也使用Code- > Reformat Code).
这是一个例子:
题
我使用的是Android Studio 3.2.1 Build#AI-181.5540.7.32.5056338,建于2018年10月8日
android android-layout android-xml android-studio android-studio-3.0