Android布局PreferenceActivity——插入layout文件

有两种方式:

1.布局文件activity_mian.xml需要添加一个ListView控件,且id为list,不然不能运行,应该是由于PreferenceActivity是一个List。


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />

<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawSelectorOnTop="false" />

</LinearLayout>

2..直接在activity中在Activity中的onCreate添加setContentView(R.layout.activity_main);

然后就可以使用findViewById去获取自定义布局下的控件.

另一种方式:

1.在xml文件中preferencescreen的布局中添加


<Preference android:layout="@layout/activity_main" android:key="youmi_ad"/>  

2.activity_mian.xml和前面相同

3. findPreference("main");

Android布局PreferenceActivity——插入layout文件,布布扣,bubuko.com

时间: 2024-08-08 13:50:55

Android布局PreferenceActivity——插入layout文件的相关文章

Android 布局学习之——Layout(布局)具体解释二(常见布局和布局參数)

 [Android布局学习系列]   1.Android 布局学习之--Layout(布局)具体解释一   2.Android 布局学习之--Layout(布局)具体解释二(常见布局和布局參数)   3.Android 布局学习之--LinearLayout的layout_weight属性   4.Android 布局学习之--LinearLayout属性baselineAligned的作用及baseline    Layout Parameters(布局參数): 在XML文件里,我们常常看到类

Android 布局学习之——Layout(布局)详解二(常见布局和布局参数)

[Android布局学习系列]   1.Android 布局学习之——Layout(布局)详解一   2.Android 布局学习之——Layout(布局)详解二(常见布局和布局参数)   3.Android 布局学习之——LinearLayout的layout_weight属性   4.Android 布局学习之——LinearLayout属性baselineAligned的作用及baseline    Layout Parameters(布局参数): 在XML文件中,我们经常看到类似与lay

Android 布局学习之——Layout(布局)详解一

layout(布局)定义了用户界面的可视化结构(visual structure),如Activity的UI,应用窗口的UI. 有两种方式声明layout: 1.在xml文件中声明UI组件. 2.在运行时,实例化布局元素.我们可以以编码的方式创建View或ViewGroup对象,操纵它们的属性. 下面用一个小例子来学习怎样以编码的方式添加layout: 1 import android.app.Activity; 2 import android.graphics.Color; 3 import

[转]【android studio】解决layout预览出现Rendering Problems Exception Unable to find the layout for Action Bar.

在android studio中打开layout文件,发现不能预览布局,提示以下错误: Rendering Problems Exception raised during rendering: Unable to find the layout for Action Bar. 解决办法:切换到design视图,选择低一点的api版本即可.

Android 布局之FrameLayout

1 FrameLayout简介 对于FrameLayout,官方介绍是:FrameLayout is designed to block out an area on the screen to display a single item. Generally, FrameLayout should be used to hold a single child view, because it can be difficult to organize child views in a way t

Android布局学习——android:gravity和android:layout_gravity的区别

[Android布局学习系列]   1.Android 布局学习之——Layout(布局)详解一   2.Android 布局学习之——Layout(布局)详解二(常见布局和布局参数)   3.Android 布局学习之——LinearLayout的layout_weight属性   4.Android 布局学习之——LinearLayout属性baselineAligned的作用及baseline 1.分别是什么?    android:gravity :        定义了一个对象在X,Y

Android开发问题之布局(layout)文件图形界面不能显示

问题解析:Android工程中Layout文件夹下的布局文件图形界面无法显示,一般发生这种情况在导入工程操作后极易出现,因为可能eclipse使用的sdk版本不同,target类型不同,所用Android自带的库文件也不同,从而导致布局文件不能正常显示图形界面,只能显示代码编辑界面.解决方法:1.右击Android工程名称,选择最后一项“属性”,在弹出框中找到“java构建路径”,然后在右边方框选择“库”标签.在“库”标签下找到Android工程的库(例如Android 4.0.3),选中“移除

Android layout文件中 &#39;?&#39; 的作用

在Android layout文件中,属性引用资源一般使用@,例如 android:textColor="@color/white" 但在一些系统文件中我们也可以看到有这样的写法 android:textColor="?android:color/textColor" 我们知道@是引用已经定义好的资源,如@color/white.@android:color/white,那 '?' 呢?下面是文档中的解释 Referencing style attributes A

android布局layout中的一些属性

1.可以使某些资源文件或UI组件可重用 <include layout="@layout/other"/> 2.定义一个文本编辑框,使用绝对定位 android:layout_x="20dip" android:layout_y="80dip" 3.控件位置 android:layout_centerHorizontal 控制该组件是否位于布局容器的水平居中位置 android:layout_centerVertical 控制该组件是