繁体   English   中英

在android xml的图形布局中正确显示CustomViews

[英]Showing CustomViews properly in Graphical Layout of android xml

我做了一个非常简单的Custom TextView。 在Android设备中一切正常。 但是在eclipse的图形布局上我只能看到编写的类名而不是TextView原始Text。 我如何在eclipse图形布局中测试它?

以下是我的代码

public class MyTextView extends TextView 
{

    public MyTextView(Context context, AttributeSet attrs, int defStyle) 
    {
        super(context, attrs, defStyle);
        init();
    }

    public MyTextView(Context context, AttributeSet attrs) 
    {
        super(context, attrs);
        init();
    }

    public MyTextView(Context context) 
    {
        super(context);
        init();
    }

    private void init() 
    {
        //if (!isInEditMode())
        {
            Typeface tf = Typeface.createFromAsset(getContext().getAssets(), "HelveticaLTStd-Bold.otf");
            setTypeface(tf);
            this.setTextColor(Color.parseColor("#FFD200"));
            this.setShadowLayer(1, 1, 1, Color.BLACK);
        }
    }

我在自定义textViews上的自定义字体有同样的问题。

图形编辑器非常多,缺乏许多功能,可以在真实设备上正常工作。

这是这样一个例子。

为了修复它,只是在isInEditMode()返回true时不加载字体,并忽略文本的样子。

事实上,也许影子功能也不能很好地工作,所以你可能也想添加它。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM