先看下列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>


更多相关文章

  1. 《android开发应用实战详解》光盘源代码
  2. Android中的人脸检测的示例代码(静态和动态)
  3. 谷歌Android为何关闭源代码?
  4. android boot 代码流程 1
  5. Android 开发常用代码

随机推荐

  1. 监听方法Android之Home键监听封装
  2. Android中View的getX,getY...
  3. Android与IOS后台机制比较
  4. Android 6.0棉花糖新特性
  5. Android获取本机电话号码的简单方法
  6. Android状态栏微技巧(推荐)
  7. Android字符串格式化
  8. Android应用程序窗口(Activity)的运行上下
  9. layout 向下一级传点击事件 descendantFo
  10. Android画图学习总结(一)——类的简介