[英]How to resize inflated layout with attribute set in Android custom view?
I am creating a custom view by inflating from a layout as following: 我正在通过从布局放大来创建自定义视图,如下所示:
CustomView.java CustomView.java
public class CustomView extends FrameLayout {
public CustomView(@NonNull Context context) {
this(context, null);
}
public CustomView(@NonNull Context context, @Nullable AttributeSet attrs) {
this(context, attrs, 0);
}
public CustomView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
LayoutInflater.from(context).inflate(R.layout.custom_view, this, true);
}
}
custom_view.xml custom_view.xml
<?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="match_parent">
...
</FrameLayout>
My problem is that when I use this custom view in the layout with some layout_width and layout_height values, the content inside does not resize with the new value. 我的问题是,当我在具有某些layout_width和layout_height值的布局中使用此自定义视图时,其中的内容不会使用新值调整大小。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.