目前项目需要在前端显示小窗口,里面包含内容比较多,有图片、按钮、文字、编辑框都可以按照一个xml格式写成layout布局了不知道自定义对话框可否显示出来如果不能,那别的思路该是什么呢?请教
解决方案 »
- android 火焰传感器数据接收处理问题
- Android 新的Activity的onCreat不显示
- ViewFlipper如何实现Button,ListView的手势滑动?
- Android手机 At指令 超级终端
- Android FrameWork中override的问题
- HttpResponse response = client.execute(httpGet)
- 请问, android应用有许多界面,在一个界面上按键会 调用另一个界面, 查找这种调用关系有什么捷径吗?
- 获取到了磁力链接,怎么实现在线播放?
- androidstudio拖动SeekBar为什么会影响其它按钮的隐藏状态?
- Error:java.lang.NullPointerException 问题求助
- 100分询问 AppWidget 上如果实现一张图片渐缩放的效果
- 怎么去掉tabhost默认的选项卡
LayoutInflater inflater=(LayoutInflater)getSystemService(LAYOUT_INFLATER_SERVICE);
View view=inflater.inflate(R.layout.inflater, null);
得到你的布局文件之后,你就可以引用你布局文件中的内容,比如:
ImageButton imageButton=(ImageButton)view.findViewById(R.id.imageButton);
取得这些控件对象之后,就可以设置它们的值了。
设置好之后,再把view添加到对话框中。使用addView(view);方法即可!
不懂的话,可以去看下这个http://blog.csdn.net/android_tutor/article/details/5513869
servicelistxml<?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="horizontal">
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content" android:orientation="horizontal">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Name:" />
<EditText android:layout_width="fill_parent"
android:layout_height="wrap_content" android:id="@+id/editName"></EditText>
</LinearLayout>
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content" android:orientation="horizontal">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Age:"></TextView>
<EditText android:layout_width="fill_parent"
android:layout_height="wrap_content" android:id="@+id/editAge" android:inputType="number"></EditText>
</LinearLayout>
</LinearLayout>
程序中使用,mainmap为ActivityLayoutInflater layoutInflater = LayoutInflater.from(mainmap);
View AddEmployee = layoutInflater.inflate(R.layout.servicelist, null);
new AlertDialog.Builder(mainmap).setTitle("更改地图").setView(
AddEmployee).setPositiveButton("应用",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//insertEmployee();
}
}).setNegativeButton("取消",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
}).show();
WindowManager m = getWindowManager();
Display d = m.getDefaultDisplay(); //为获取屏幕宽、高 WindowManager.LayoutParams p = getWindow().getAttributes();
//获取对话框当前的参数值
p.x = 0; //设置位置 默认为居中
p.y = 0; //设置位置 默认为居中
p.height = (int) (d.getHeight() * 0.5); //高度设置为屏幕的0.6
p.width = (int) (d.getWidth() * 0.5); //宽度设置为屏幕的0.95
this.getWindow().setAttributes((android.view.WindowManager.LayoutParams) p);一下子把Activity都变小了
v.setMinimumWidth(***);已经实现了,嘿嘿