Android效果:FrameLayout实现中间头像的Dialog

1.Dialog布局

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@android:color/transparent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/dp_35"
        android:background="@color/white"
        android:gravity="center_horizontal"
        android:orientation="vertical">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/dp_50"
            android:gravity="center_horizontal"
            android:orientation="horizontal">

            <TextView
                android:id="@+id/txt_name"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="冒险样"
                android:textColor="@color/text_color_normal"
                android:textSize="@dimen/font_size_25sp" />

            <ImageView
                android:id="@+id/img_statue"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

        </LinearLayout>

        <TextView
            android:id="@+id/txt_phone"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/dp_10"
            android:text="13410268689"
            android:textColor="@color/text_color_normal"
            android:textSize="@dimen/font_size_16sp" />

        <Button
            android:id="@+id/btn_say_hello"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="@dimen/dp_20"
            android:layout_marginRight="@dimen/dp_20"
            android:background="@drawable/logout"
            android:layout_marginTop="@dimen/dp_20"
            android:layout_marginBottom="@dimen/dp_20"
            android:text="即可打招呼 获见面大礼"
            android:textColor="@color/white"
            android:textSize="@dimen/font_size_20sp" />
    </LinearLayout>

    <com.meitianhui.convenitenbuy.widget.CircleImageView
        android:id="@+id/imgHead"
        android:layout_width="@dimen/dp_70"
        android:layout_height="@dimen/dp_70"
        android:layout_gravity="top|center_horizontal"
        android:src="@drawable/commfra_img_jx" />
</FrameLayout>
2.AS预览图


3.java代码

public class SayHelloDialog extends Dialog {
    private Context mContext;
    private Activity mActivity;
    private SayHelloClickListener listener;
    private CircleImageView imgHead;//
    private TextView txt_name;//
    private ImageView img_statue;//等级
    private TextView txt_phone;//电话
    private Button btn_say_hello;//跳转
    public SayHelloDialog(Context context, SayHelloClickListener l) {
        super(context);
        this.mContext = context;
    }

    public SayHelloDialog(Activity context, int themeResId, SayHelloClickListener l) {
        super(context, themeResId);
        mContext = context;
        mActivity = context;
        this.listener = l;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_say_hello);

        DisplayMetrics metric = new DisplayMetrics();
        mActivity.getWindowManager().getDefaultDisplay().getMetrics(metric);
        WindowManager.LayoutParams p = getWindow().getAttributes();
        p.width = (int) (metric.widthPixels - 100);
        Window window = getWindow();
        window.setAttributes(p);
        window.setGravity(Gravity.CENTER);
        setCancelable(true);
        this.setCanceledOnTouchOutside(true);

        imgHead = (CircleImageView)findViewById(R.id.imgHead);
        txt_name = (TextView)findViewById(R.id.txt_name);
        txt_phone = (TextView)findViewById(R.id.txt_phone);
        img_statue = (ImageView) findViewById(R.id.img_statue);
        btn_say_hello = (Button) findViewById(R.id.btn_say_hello);

        btn_say_hello.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                listener.sayHello();
                dismiss();
            }
        });
    }

    public interface SayHelloClickListener {
        public void sayHello();
    }

}

4.实现的效果图


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值