Mer*_*dik 4 android android-layout
如何在Android的警告对话框的顶角放置关闭按钮?
在警告对话框中将关闭按钮放在右上角.
我使用下面的代码滚动和对话框
<ScrollView
android:id="@+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:scrollbars="vertical"
android:scrollbarAlwaysDrawVerticalTrack="true" >
Run Code Online (Sandbox Code Playgroud)
<ImageVieandroid:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="200dp"
android:src="@drawable/ic_launcher" />
</RelativeLayout>
</ScrollView>
Run Code Online (Sandbox Code Playgroud)
在java编码我已经使用下面的编码我想把图像关闭对话框请帮忙
public void onClick(View v)
{
// TODO Auto-generated method stub
switch (v.getId())
{
case R.id.How_to_use:
final Dialog dialog = new Dialog(this);
dialog.setContentView(R.layout.description);
dialog.setTitle("How to use");
TextView text = (TextView) dialog.findViewById(R.id.description);
text.setText(R.string.Descr_How_to_use);
ImageView image = (ImageView) dialog.findViewById(R.id.image);
image.setImageResource(R.drawable.ic_launcher);
image.setOnClickListener(new OnClickListener()
{
// @Override
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.show();
break;
default:
break;
}
Run Code Online (Sandbox Code Playgroud)
aB9*_*aB9 12
我知道,我迟到了回答这个2岁的问题,但这个问题适用于那些不知道正确方法的人....
(每个人都建议)使用自定义对话框.
使用RelativeLayout作为custom_dialog.xml的主要布局,因为您必须在主窗口的右上角(右/左)浮动该取消按钮.
custom_dialog.xml
<?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="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="400dp"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="15dp"
android:background="#F4F4F4">
<!--Main Body of your custom dialog-->
</RelativeLayout>
<LinearLayout
android:id="@+id/llTop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:orientation="vertical">
<ImageButton
android:id="@+id/btnCancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/btnBookK"
android:background="@null"
android:src="@drawable/ic_close" />
</LinearLayout>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
在自定义对话框代码中,使用以下行使其透明:
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
Run Code Online (Sandbox Code Playgroud)
小智 1
你必须创建自定义对话框
import android.app.Dialog;
import android.content.Context;
public class CustomDialog extends Dialog
{
public CustomDialog(Context context)
{
super(context);
setContentView(R.layout.dialog);
}
}
Run Code Online (Sandbox Code Playgroud)
创建dialog.xml 文件。根据您的要求设计。
| 归档时间: |
|
| 查看次数: |
20718 次 |
| 最近记录: |