未解决问题

@、

1、自定义了一个RelativeLayout类MyCustomLayout,然后在onDraw(...)中,画一个圆canvas.drawCircle(...)。

2、自定义了一个Dialog类MyDialog,其中xml中是RelativeLayout,并且layout_height和layout_width都是match_parent,然后在onCreate(...)中,创建一个MyCustomLayout。

3、在MainActivity中创建MyDialog,然后show。

问题:

1、为什么在MyCustomLayout的构造函数中调用了setBackgroundColor(...),画的圆才能显示。

2、为什么在MyDialog.onCreate()中创建MyCustomLayout变量的LayoutParams不能设置为wrap_conent。

代码:

public class MyCustomLayout extends RelativeLayout {
    private static final String TAG = "My--CustomView";

    private int mRadius = 5;

    public MyCustomLayout(Context context) {
        super(context);
        Log.d(TAG, "Constructor1");
        // Why have to call this ??
        setBackgroundColor(getResources().getColor(
                android.R.color.transparent));
    }

    public MyCustomLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
        Log.d(TAG, "Constructor2");
        setBackgroundColor(getResources().getColor(
                android.R.color.transparent));
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

//        canvas.drawColor(Color.parseColor("#000000"));
        Paint paint = new Paint();
        paint.setAntiAlias(true);
        paint.setColor(Color.parseColor("#FFFF00"));
        Log.d(TAG, getWidth() + " -- " + getHeight() + " -- " + Utils.dpToPx(mRadius, getResources()));
        canvas.drawCircle(getWidth() / 2, getHeight() / 2, Utils.dpToPx(mRadius, getResources()), paint);
    }

    public int getRadius() {
        return mRadius;
    }

    public void setRadius(int radius) {
        mRadius = radius;
        invalidate();
    }
}

MyCustomLayout.java

class MyDialog extends Dialog {
       MyCustomLayout mMyCustomLayout;

        public MyDialog(Context context) {
            super(context, android.R.style.Theme_Translucent);
        }

        @Override
        public void show() {
            super.show();
            Log.d("MyDialog", "show");
        }

        @Override
        public void dismiss() {
            super.dismiss();
            Log.d("MyDialog", "dismiss");
//            mMyCustomView.setRadius(0);
        }

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            requestWindowFeature(Window.FEATURE_NO_TITLE);
            super.onCreate(savedInstanceState);
            setContentView(R.layout.my_dialog);

            Log.d("MyDialog", "onCreate");

            RelativeLayout content = (RelativeLayout) this
                    .findViewById(R.id.my_custom_view_content);
            mMyCustomLayout = new MyCustomLayout(this.getContext());
            content.addView(mMyCustomLayout);

            mMyCustomLayout.setLayoutParams(
                    new RelativeLayout.LayoutParams(
                            RelativeLayout.LayoutParams.FILL_PARENT,
                    RelativeLayout.LayoutParams.FILL_PARENT));
        }
    }

MyDialog.java

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:id="@+id/my_custom_view_content"
                android:layout_width="match_parent"
                android:layout_height="match_parent">
 </RelativeLayout>

my_dialog.xml

时间: 2024-07-29 02:23:43

未解决问题的相关文章

未解决问题:指针作参数、二重指针、指针数组、动态内存分配

题目:输入m个学生n门课的成绩,计算每个学生的平均成绩,输入学生编号后输出该学生各门课的成绩. 先直接上源码:(有错误的源码) #include <stdio.h> #include <stdlib.h> #include <stdbool.h> int **pointer_counterpart = NULL; int main() { void Input_number(int *m, int *n); //输入m个学生n门课成绩 void allocation(i

【Java EE 学习第77天】【数据采集系统第九天】【使用spring实现答案水平分库】【未解决问题:分库查询问题】

之前说过,如果一个数据库中要存储的数据量整体比较小,但是其中一个表存储的数据比较多,比如日志表,这时候就要考虑分表存储了:但是如果一个数据库整体存储的容量就比较大,该怎么办呢?这时候就需要考虑分库了,就是建立多个数据库保存数据.这里以答案为例,就算调查对象不是很多,但是参与调查的人数非常多,那么需要保存的数据量就会非常大,怎样将答案以一种规则保存到不同的数据库中就是现在需要考虑的问题(查询分库的问题未解决,先存档). 一.分库方法 分库分为水平分库和竖直分库两种类型. (1)水平分库 数据库之间

未解决问题:

1 - (NSMutableArray *)houseTypes { 2 ATTypeCellViewModel *typeVM1 = [ATTypeCellViewModel new]; 3 typeVM1.type = @"整租"; 4 typeVM1.isSelected = YES; 5 6 ATTypeCellViewModel *typeVM2 = [ATTypeCellViewModel new]; 7 typeVM2.type = @"合租"; 8

【未解决问题】指针

1 void GetMemory(char* p) 2 { 3 p=(char*)malloc(100); 4 } 5 void Test(void) 6 { 7 char *str=NULL; 8 GetMemory(str);//改为&str 9 strcpy(str,"helloworld"); 10 printf(str); 11 } 按照注释改能运行了,但是不知道为什么······· 原文地址:https://www.cnblogs.com/HY12345/p/964

error C2065:未声明的标识符错误

原文地址:http://blog.sina.com.cn/s/blog_8216ada701017evx.html 在VS2010下进行VC++调试时,出现这样一种错误:error C2065:未声明的标识符,当时感觉十分怪异,为什么说怪异呢?因为如果在.cpp中未引入相关.h文件出现这样的错误很正常,但是现在是已经引入了相关的头文件,却还是出现了诸如error C2065.error C2087.error C2133...的错误. 情况是这样的,新建了一个工程项目,想使用其他工程中定义的同一

【转】数学之美番外篇:平凡而又神奇的贝叶斯方法----刘未鹏

概率论只不过是把常识用数学公式表达了出来. --拉普拉斯 记得读本科的时候,最喜欢到城里的计算机书店里面去闲逛,一逛就是好几个小时:有一次,在书店看到一本书,名叫贝叶斯方法.当时数学系的课程还没有学到概率统计.我心想,一个方法能够专门写出一本书来,肯定很牛逼.后来,我发现当初的那个朴素归纳推理成立了--这果然是个牛逼的方法. --题记 目录 0. 前言1. 历史    1.1 一个例子:自然语言的二义性    1.2 贝叶斯公式2. 拼写纠正3. 模型比较与贝叶斯奥卡姆剃刀    3.1 再访拼

can not be cast to javax.servlet.Filter等问题的解决方法

问题1:can not be cast to javax.servlet.Filter 一位从测试转开发的同事首次更新代码,并编译在本地启动web项目时,报如下错误: Exception starting filter encodingFilterjava.lang.ClassCastException:com.gaochao.platform.web.context.filter.ContextFilter2 can not be cast to javax.servlet.Filter 根据

hibernate 连接 mysql 乱码的情况

在本地开发环境中,一切正常,部署到服务器后(windows 2003 + tomcat)含有中文的查询和表单提交都有乱码,从以下几个方面检查并解决了问题: 1.将所有jsp.js.css文件默认编码改为了utf-8,未解决问题. 2.struts2的配置文件中加入了节点:<constant name="struts.i18n.encoding" value="UTF-8" />  ,未解决问题. 3.web.xml中做如下确认和修改,未解决问题. <

第九小组

一:PTA题目集 1 删除单链表偶数节点实现在pta上未能满分,运行后如果第一位数是偶数则输出错误,一下为我们的代码 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 struct ListNode *createlist() {     struct ListNode *r,*s,*L,*head;     int n,i=0;     L=(struct L