自定义一个dialog 里面夹带scrollView



 
 <?xml version="1.0" encoding="utf-8"?>
 
<RelativeLayout android:id="@+id/RelativeLayout01" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
xmlns:android="http://schemas.android.com/apk/res/android">
 
<TextView android:id="@+id/TextView01" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:text="This is my main activity, from here, I want to display a dialog, after the user clicked the button below this text.">
</TextView>
 
<Button android:layout_height="wrap_content" 
android:layout_below="@+id/TextView01" 
android:layout_width="wrap_content" 
android:id="@+id/Button01main" 
android:text="Hey! There is more..."></Button>
 
</RelativeLayout>

 dialog's layout, maindialog.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="wrap_content" android:layout_height="wrap_content">
 
<ImageView android:id="@+id/ImageView01"
 android:layout_width="wrap_content" android:layout_height="wrap_content"
 android:layout_centerHorizontal="true" />
 
 <ScrollView android:id="@+id/ScrollView01"
 android:layout_width="wrap_content" android:layout_below="@+id/ImageView01"
 android:layout_height="200px">
 
 <TextView android:text="@+id/TextView01" android:id="@+id/TextView01"
 android:layout_width="wrap_content" android:layout_height="wrap_content" />
 
 </ScrollView>
 
 <Button android:id="@+id/Button01" android:layout_below="@id/ScrollView01"
 android:layout_width="wrap_content" android:layout_height="wrap_content"
 android:layout_centerHorizontal="true" android:text="Cancel" />
 
</RelativeLayout>

 

public class main extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //set up main content view
        setContentView(R.layout.main);
        //this button will show the dialog
        Button button1main = (Button) findViewById(R.id.Button01main);
 
        button1main.setOnClickListener(new OnClickListener() {
        @Override
            public void onClick(View v) {
                //set up dialog
                Dialog dialog = new Dialog(main.this);
                dialog.setContentView(R.layout.maindialog);
                dialog.setTitle("This is my custom dialog box");
                dialog.setCancelable(true);
                //there are a lot of settings, for dialog, check them all out!
 
                //set up text
                TextView text = (TextView) dialog.findViewById(R.id.TextView01);
                text.setText(R.string.lots_of_text); 
 
                //set up image view
                ImageView img = (ImageView) dialog.findViewById(R.id.ImageView01);
                img.setImageResource(R.drawable.nista_logo);
 
                //set up button
                Button button = (Button) dialog.findViewById(R.id.Button01);
                button.setOnClickListener(new OnClickListener() {
                @Override
                    public void onClick(View v) {
                        finish();
                    }
                });
                //now that the dialog is set up, it's time to show it    
                dialog.show();
            }
        });
    } 
 }

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值