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")
@Override
protected 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();
}
}
LayoutInflater
最新推荐文章于 2024-07-01 14:09:00 发布