在Android的绘制边界问题 [英] Problems with drawing a border in android
本文介绍了在Android的绘制边界问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想实现边框包裹我的EditText这样在此的给出答案链接。
然而,当我试图夸大它来尝试它是如何工作的,我得到一个错误
android.view.InflateException:二进制XML文件行#4:错误充气类形状
为什么会这样?
修改
我在XML文件中粘贴此(edittext.xml)
<的FrameLayout的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT><形状
机器人:形状=矩形>
[固体机器人:颜色=#FAFAD2/>
<行程机器人:宽=1SP机器人:颜色=#000000
机器人:dashWidth =7SP机器人:dashGap =5SP/>
< /形状>< /&的FrameLayout GT;
公共类编辑框扩展视图{ 私人LayoutInflater layoutInflater;
私人的FrameLayout viewLayout; 公共编辑框(上下文的背景下){
超级(上下文); 尝试{
layoutInflater =(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
viewLayout =(的FrameLayout)layout_inflater.inflate(R.layout.edittext,NULL); }赶上(例外五){
e.printStackTrace();
}
} 公共查看getView(){
返回viewLayout;
}
}
解决方案
形状在XML中可绘制文件夹应该定义
I am trying to achieve a border to wrap my edittext like this given in the answer of this link.
However, when I tried inflating it to try out how it works, I get an error
android.view.InflateException: Binary XML file line #4: Error inflating class shape
Why is this so?
EDIT
I pasted this in an XML file (edittext.xml)
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<shape
android:shape="rectangle">
<solid android:color="#FAFAD2" />
<stroke android:width="1sp" android:color="#000000"
android:dashWidth="7sp" android:dashGap="5sp" />
</shape>
</FrameLayout>
public class EditBox extends View {
private LayoutInflater layoutInflater;
private FrameLayout viewLayout;
public EditBox(Context context) {
super(context);
try {
layoutInflater = (LayoutInflater) context.getSystemService (Context.LAYOUT_INFLATER_SERVICE);
viewLayout = (FrameLayout) layout_inflater.inflate(R.layout.edittext, null);
} catch(Exception e) {
e.printStackTrace();
}
}
public View getView() {
return viewLayout;
}
}
解决方案
the shape should define in xml in drawable folder
这篇关于在Android的绘制边界问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文