繁体   English   中英

将edittext添加到自定义视图

[英]Adding edittext into a custom view

我有一个自定义视图,看起来有点像里程表。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:slider="http://schemas.android.com/apk/res-auto"
    android:id="@+id/layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

<com.mysite.view.SeekBar_Speedometer
    android:id="@+id/slider"
    slider:fill_clockwise_color="@color/lightgrey"
    slider:fill_anticlockwise_color="@color/blue"
    slider:fill_handle_color="@color/green"
    slider:fill_handle_width="3"
    slider:angle_start="120"
    slider:angle_end="60"
    slider:fill_start_angle="120"
    slider:score_min="0"
    slider:score_max="300"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" />

</LinearLayout>

我想在里程表的中央添加一个edittext。

就像您可以在画布上绘制文本一样,我可以从视图内部以相同的方式添加edittext吗? 我不这么认为!

问题是,如何将这个edittext添加到我的自定义视图中?

在您的自定义视图类中,您可以执行以下操作:

EditText edit = new EditText(context);
addView( edit );

为此,您的自定义视图必须扩展ViewGroup(LinearLayout,RelativeLayout等)。

暂无
暂无

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

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