[英]Android, CustomView Layout not showing
I've done this before with no issue so i know my mistake is subtle. 我之前没有做过此事,所以我知道我的错误很细微。
picker_dialog_layout.xml:
picker_dialog_layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="left|center_horizontal"
android:id="@+id/pickerDialog_title"
android:text="HELLO WORLD!!"/>
<NumberPicker
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/pickerDialog_title"
android:id="@+id/pickerDialog_selector"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/pickerDialog_selector"
android:orientation="horizontal">
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="5"
android:id="@+id/pickerDialog_cancel"
android:gravity="center"
android:text="Cancel"/>
<Button
android:layout_height="match_parent"
android:layout_width="0dp"
android:layout_weight="5"
android:id="@+id/pickerDialog_set"
android:gravity="center"
android:text="Set"/>
</LinearLayout>
</merge>
During the Custom Class constructor, PickerDialog(Context context, AttributeSet attrs, int defStyle)
i call: 在自定义类构造函数期间
PickerDialog(Context context, AttributeSet attrs, int defStyle)
我调用PickerDialog(Context context, AttributeSet attrs, int defStyle)
:
LayoutInflater.from(context).inflate(R.layout.picker_dialog_layout, this);
And in the parent XML: 并在父XML中:
<com.company.simonaddicott.controlpanel_1.PickerDialog
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/pickerDialog" />
The view itself does show, and from using layout bound tools in developer tools i can identify that the ui elements are present, or at least the boundaries are present (see below) 该视图本身确实可以显示,并且通过在开发人员工具中使用布局绑定工具,我可以识别出存在ui元素,或者至少存在边界(请参见下文)
What am i missing from this to make there UI elements appear like they should??
我从中缺少什么来使UI元素看起来像应该的那样??
My mistake was that I extended the custom view by LinearLayout
, but was using RelativeLayout
positioning on the picker_dialog_layout.xml
. 我的错误是我通过
LinearLayout
扩展了自定义视图,但是在picker_dialog_layout.xml
上使用了RelativeLayout
定位。
The elements inside the layout were not showing as they had no relative parent element to be positioned against 布局内的元素未显示,因为它们没有相对的父元素要定位
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.