LayoutInflater

来源:互联网 发布:linux怎么改变用户目录 编辑:程序博客网 时间:2024/05/01 17:36
package com.example.android_test_1206;import android.annotation.SuppressLint;import android.app.Activity;import android.app.AlertDialog;import android.content.Context;import android.os.Bundle;import android.view.LayoutInflater;import android.view.View;import android.widget.RelativeLayout;public class MainActivity extends Activity {public MainActivity(){super();}@SuppressLint("NewApi")@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);// 当这样的话,// 默认调用inflate(R.layout.fragment_main,null,false);// 为false,则null仅被用来创建在xml文件中的root viewgroup的layoutparams。// 即为:layout_height和layout_width均为wrap_content.// 参数root不作为 xml文件的root// 此时,root为null,则创建的layoutparams则为默认情况。RelativeLayout relativeLayout1 = (RelativeLayout) LayoutInflater.from(getBaseContext()).inflate(R.layout.fragment_main, null);Context context=getBaseContext();RelativeLayout relativeLayout2 = (RelativeLayout) LayoutInflater.from(getBaseContext()).inflate(R.layout.fragment_main, null, false);AlertDialog.Builder builder=new AlertDialog.Builder(MainActivity.this);AlertDialog.Builder builder2=new AlertDialog.Builder(getBaseContext());//.inflate(R.layout.item_row,null,false)View content = LayoutInflater.from(getBaseContext()).inflate(R.layout.item_row, null); builder.setTitle("My Dialog");builder.setView(content);builder.setPositiveButton("OK", null);builder.show();}}

0 0
原创粉丝点击