先看下列xml代码:
<?xml
version="1.0"
encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/wordBgRL"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<Button
android:id="@+id/dictionaryButton"
android:background="@drawable/dictionary_btn_bg"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
style="@style/WrapContentWidgetStyle"
/>
</RelativeLayout>
在java代码里取出wordBgRL 始终为null;
wordBgRL = (RelativeLayout)findViewById(R.id.wordBgRL); // wordBgRL alwasys == null
dictionaryButton = (Button)findViewById(R.id.dictionaryButton); //dictionaryButton != null
后来发现你必须自己另写一个RelativeLayout,可能因为xmlns:android="http://schemas.android.com/apk/res/android" 它存在的原因吧。
<?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"
>
<RelativeLayout
android:id="@+id/wordBgRL"
style="@style/FillParentWidgetStyle"
>
<Button
android:id="@+id/dictionaryButton"
android:background="@drawable/dictionary_btn_bg"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
style="@style/WrapContentWidgetStyle"
/>
</RelativeLayout>
</RelativeLayout>
分享到:
相关推荐
Android中使用xml文件定义颜色资源.pdf 学习资料 复习资料 教学资源
使用指南:PhoneGap的CordovaWebView组件在Android原生项目中使用. 1.下载phonegap2.0, 1.1 从解压文件中“phonegap-phonegap-2dbbdab\lib\android”中可以看到以下文件: cordova-2.0.0.jar、cordova-2.0.0.js和...
Android中使用XML文件定义字符串.pdf 学习资料 复习资料 教学资源
SOAP:XML跨平台Web Service开发技术
Android Studio 在xml文件中设置界面布局1、xml文件中给输入框editText修改下划线颜色2、设置button按钮为圆角及修改按钮颜色3、运用约束布局时预览效果和运行效果不一致 写一写今天困扰我很久的问题:如何给...
Android学习笔记(六):xml和widget
全书一共被压缩为5个rar,这是第四个!!!! 其他的请看ID:ljtt123(本人分享) 本博客提供的所有教程的资源原稿均来自于互联网,仅供学习交流之用,切勿进行商业传播。同时,转载时不要移除本申明。如产生任何...
添加color.xml后设置背景白色,下面一行即可 android:background="@color/white
java&android;解析xml 将xml转换为json java&android;解析xml 将xml转换为json 原文地址:https://blog.csdn.net/u010838785/article/details/82258411
上篇博文代码实现了Android自带的preference组件,本文将通过实例讲解自定义preference组件。 主要通过以下几步来实现: 1.定义需要的layout布局res->layout->xml文件; 2.通过继承Preference类,来实现自定义...
android 国际化 String.xml Excel 相互转换工具
Android 工程里面values文件夹有dimens.xml文件,为了适配不同的分辨率,例如values-sw400dp,values-sw600dp,values-sw720dp,如果自己去生成这几个文件夹,需要根据values里面的dimens.xml进行计算,然后修改,这个...
android开发中有时会想研究借鉴一下设计思路和UI风格,但解压apk包后 layout文件夹下xml文件一般都是加密的。在网上找到了一个工具,可以完美地解密xml文件,但这个工具的使用方法是:调cmd 然后...
自制工具,将AndroidStudio 的 VectorDrawable xml 资源逆向转回 svg文件方便编辑。工具为带js的html,上方输入框贴入xml,下方输入框输出svg代码结果以及svg预览 注意目前仍未支持渐变填充
Android中在xml中静态添加Fragment 在activity_main.xml中添加LeftFragment和RightFragment
pom.xml android maven 工程 如何拿Maven 构建 一个 Android 项目的pom配置
Android 报错:Entry name ‘AndroidManifest.xml’ collided前言解决方法1、直接退回3.5.32、排除打包文件3、使用旧打包工具4、最终解决方法完事 前言 这两天 Android studio 更新了 3.6 版本,天天在右下角提示 ...
android:drawable.xml相关应用,对android开发有帮助的文档。
pull解析xml文件,和sax和dom一样 都可以脱离android单独使用,pull和sax的原理一样,不一样的地方是pull读取xml文件后调用方法返回的是数字, 读取到xml的声明返回数字0 START_DOCUMENT; 读取到xml的结束返回数字1 ...
android XMl 解析神奇xstream 二: 把对象转换成xm