gpt4 book ai didi

android - 将 textView 添加到自定义 Android View

转载 作者:太空狗 更新时间:2023-10-29 14:41:43 25 4
gpt4 key购买 nike

我有以下 View,我想向其中添加一个 TextView。有谁知道如何做到这一点?

public class ProgressView extends View {

TextView text;

public ProgressView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
text = new TextView(getContext());
text.setText("Hello");
// How can I add this to the view now??
}

@Override
protected void onDraw(final Canvas canvas) {

}
}

最佳答案

您不能将 View 添加到另一个 View,而是添加到 ViewGroup。如果你想让它成为一个自定义的ViewGroup,你必须实现onLayout()

关于android - 将 textView 添加到自定义 Android View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46982897/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com