我遇到的问题是我创建的Custom Relative Layout类导致父XML布局中的其他组件消失或不显示。
我可以在布局中添加一些内容,还是会阻止列出的第一个XML代码中的所有其他布局/组件不显示?
XML实施 - 工具栏布局
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<com.l.mapprototype.view.ToolbarLayout
android:id="@+id/primary_toolbar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<View
android:id="@+id/profile_sep_view"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="@+id/primary_toolbar_layout"
android:background="#ffcccccc" />
<com.l.mapprototype.font.RobotoTextView
android:id="@+id/ap_profile_not_found_tv"
style="@style/TextViewAppearance.Body1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/ap_action_btn_wrap"
android:layout_below="@+id/profile_sep_view"
android:gravity="center"
android:text="Profile Not Found"
android:visibility="gone"
app:typeface="robotoBold" />
<ScrollView
android:id="@+id/ap_fields_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/ap_action_btn_wrap"
android:layout_below="@+id/profile_sep_view"
android:visibility="visible" >
<LinearLayout
android:id="@+id/ap_fields_linearlayout_parent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/ap_fields_linearlayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg_card"
android:orientation="vertical"
android:padding="10dp" >
<LinearLayout
android:id="@+id/ap_first_name_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/ap_firstname_imageview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/user_icon" />
<EditText
android:id="@+id/ap_first_name_et"
style="@style/EditTextStyle.Standard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:ems="10"
android:hint="First Name"
android:inputType="textPersonName"
android:padding="10dp"
tools:ignore="HardcodedText" />
</LinearLayout>
<LinearLayout
android:id="@+id/ap_last_name_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/ap_lastname_imageview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/user_icon" />
<EditText
android:id="@+id/ap_last_name_et"
style="@style/EditTextStyle.Standard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:ems="10"
android:hint="Last Name"
android:inputType="textPersonName"
android:padding="10dp"
tools:ignore="HardcodedText" />
</LinearLayout>
<LinearLayout
android:id="@+id/ap_phonenum_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/ap_phonenum_imageview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/phonenumber_icon" />
<EditText
android:id="@+id/ap_phonenum_et"
style="@style/EditTextStyle.Standard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:ems="10"
android:hint="Phone Number"
android:inputType="phone"
android:padding="10dp"
tools:ignore="HardcodedText" />
</LinearLayout>
<LinearLayout
android:id="@+id/ap_email_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/ap_email_imageview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/email_icon" />
<EditText
android:id="@+id/ap_email_et"
style="@style/EditTextStyle.Standard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:ems="10"
android:hint="Email Address"
android:inputType="textWebEmailAddress"
android:padding="10dp"
tools:ignore="HardcodedText" />
</LinearLayout>
<LinearLayout
android:id="@+id/ap_username_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/ap_username_imageview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/user_icon" />
<EditText
android:id="@+id/ap_username_et"
style="@style/EditTextStyle.Standard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:ems="10"
android:hint="Username"
android:inputType="textPersonName"
android:padding="10dp"
tools:ignore="HardcodedText" />
</LinearLayout>
<LinearLayout
android:id="@+id/ap_password_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/ap_password_imageview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/password_icon" />
<EditText
android:id="@+id/ap_password_et"
style="@style/EditTextStyle.Standard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:ems="10"
android:hint="Password"
android:inputType="textPassword"
android:padding="10dp"
tools:ignore="HardcodedText" />
</LinearLayout>
<LinearLayout
android:id="@+id/ap_confirm_password_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/ap_confirm_password_imageview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/password_icon" />
<EditText
android:id="@+id/ap_confirm_passwork_et"
style="@style/EditTextStyle.Standard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:ems="10"
android:hint="Confirm password"
android:inputType="textPassword"
android:padding="10dp"
tools:ignore="HardcodedText" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/ap_gratuity_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginTop="5dp"
android:background="@drawable/bg_card"
android:orientation="vertical"
android:padding="10dp" >
<LinearLayout
android:id="@+id/ap_gratuity_label_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<com.l.mapprototype.font.RobotoTextView
android:id="@+id/ap_gratuity_label"
style="@style/TextViewAppearance.Body2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="Default Gratuity Percent"
app:typeface="robotoBold" />
<com.l.mapprototype.font.RobotoTextView
android:id="@+id/ap_gratuity_label_value"
style="@style/TextViewAppearance.Body1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="5dp"
android:gravity="center"
android:text=""
app:typeface="robotoRegular" />
<SeekBar
android:id="@+id/ap_gratuity_seekbar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
<CheckBox
android:id="@+id/ap_charge_agreement_cb"
style="@style/EditTextStyle.Standard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="I agree with future credit card or account charges"
tools:ignore="HardcodedText" />
<TextView
android:id="@+id/ap_charges_agreement_tv"
style="@style/TextViewAppearance.Body1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:linksClickable="true"
android:text="@string/readchargesagreement" />
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="@+id/ap_action_btn_wrap"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#ffefefef"
android:orientation="vertical" >
</LinearLayout>
<!-- <Button -->
<!-- android:id="@+id/ap_action_button" -->
<!-- android:layout_width="match_parent" -->
<!-- android:layout_height="70dp" -->
<!-- android:layout_alignParentBottom="true" -->
<!-- android:layout_margin="10dp" -->
<!-- android:background="@drawable/round_corners_shape_00428_selector" -->
<!-- android:padding="10dp" -->
<!-- android:textColor="@color/white" -->
<!-- android:textSize="24sp" /> -->
</RelativeLayout>
ToolbarLayout Class
public class ToolbarLayout extends RelativeLayout {
private Toolbar toolbar;
private IconView toolbarLeftLogo;
private ImageView toolbarTitleIcon;
private TextView toolbarTitle;
private Context context;
public ToolbarLayout(Context context) {
super(context);
this.context = context;
if (!isInEditMode()) {
init();
}
}
public ToolbarLayout(Context context, AttributeSet attrs) {
super(context, attrs);
this.context = context;
if (!isInEditMode()) {
init();
}
}
public ToolbarLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
this.context = context;
if (!isInEditMode()) {
init();
}
}
private void init() {
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
RelativeLayout rootView = (RelativeLayout) inflater.inflate(R.layout.toolbar_layout, this);
toolbar = (Toolbar) rootView.findViewById(R.id.general_toolbar);
toolbarLeftLogo = (IconView) rootView.findViewById(R.id.general_toolbar_left_logo);
toolbarTitleIcon = (ImageView) rootView.findViewById(R.id.general_toolbar_title_icon);
toolbarTitle = (TextView) rootView.findViewById(R.id.general_toolbar_title);
toolbarLeftLogo.setIcon("company_logo.png");
}
public void setActionBarTitle(String title) {
if (title == null) {
toolbarTitleIcon.setVisibility(View.VISIBLE);
toolbarTitle.setVisibility(View.GONE);
toolbarLeftLogo.setVisibility(View.GONE);
} else {
toolbarTitleIcon.setVisibility(View.GONE);
toolbarTitle.setVisibility(View.VISIBLE);
toolbarTitle.setText(title);
toolbarLeftLogo.setVisibility(View.VISIBLE);
}
}
public void setToolbarTitleText(String title) {
if (title != null) {
toolbarTitle.setText(title);
}
}
}
toolbar_layout由ToolbarLayout类夸大的XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<android.support.v7.widget.Toolbar
android:id="@+id/general_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ffffffff"
android:minHeight="?attr/actionBarSize"
android:visibility="visible" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="60dp" >
<com.l.mapprototype.view.IconView
android:id="@+id/general_toolbar_left_logo"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:visibility="gone"
tools:ignore="RtlHardcoded" />
<ImageView
android:id="@+id/general_toolbar_title_icon"
android:layout_width="wrap_content"
android:layout_height="60dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:padding="10dp"
android:src="@drawable/company_title_icon"
tools:ignore="ContentDescription" />
<com.l.mapprototype.font.RobotoTextView
android:id="@+id/general_toolbar_title"
style="@style/TextViewAppearance.Headline1"
android:layout_width="wrap_content"
android:layout_height="60dp"
android:layout_centerVertical="true"
android:layout_gravity="center"
android:layout_toRightOf="@+id/general_toolbar_left_logo"
android:gravity="center_vertical|center_horizontal"
android:padding="10dp"
android:visibility="gone" />
</RelativeLayout>
</android.support.v7.widget.Toolbar>
</RelativeLayout>
答案 0 :(得分:0)
我设法让一切正常运转。这是我在 pskink 的帮助下得出的解决方案。
ToolbarLayout Class
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<form id="popup1" method="post">
<fieldset>
<input id="pEmail" type="text" placeholder="E-mail" value="E-mail" onclick="this.value=''" class="popup_input" name="pEmail" type="text" />
<label id="pEmailError" style="color:#FF0000; display:none;">Error</label>
<button type="submit" id="nPopupSubmit" name="nPopupSubmit">Go !</button>
</fieldset>
</form>
<强> toolbar_layout 强>
public class ToolbarLayout extends RelativeLayout {
private Toolbar toolbar;
private IconView toolbarLeftLogo;
private ImageView toolbarTitleIcon;
private TextView toolbarTitle;
private Context context;
public ToolbarLayout(Context context) {
super(context);
this.context = context;
if (!isInEditMode()) {}
}
public ToolbarLayout(Context context, AttributeSet attrs) {
super(context, attrs);
this.context = context;
if (!isInEditMode()) {}
}
public ToolbarLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
this.context = context;
if (!isInEditMode()) {}
}
@Override
protected void onFinishInflate() {
super.onFinishInflate();
this.toolbar = (Toolbar) findViewById(R.id.general_toolbar);
this.toolbarLeftLogo = (IconView) findViewById(R.id.general_toolbar_left_logo);
this.toolbarTitleIcon = (ImageView) findViewById(R.id.general_toolbar_title_icon);
this.toolbarTitle = (TextView) findViewById(R.id.general_toolbar_title);
toolbarLeftLogo.setIcon("company_logo.png");
}
public void setActionBarTitle(String title) {
if (title == null) {
toolbarTitleIcon.setVisibility(View.VISIBLE);
toolbarTitle.setVisibility(View.GONE);
toolbarLeftLogo.setVisibility(View.GONE);
} else {
toolbarTitleIcon.setVisibility(View.GONE);
toolbarTitle.setVisibility(View.VISIBLE);
toolbarTitle.setText(title);
toolbarLeftLogo.setVisibility(View.VISIBLE);
}
}
public void setToolbarTitleText(String title) {
if (title != null) {
toolbarTitle.setText(title);
}
}
}
<强>实施强>
<?xml version="1.0" encoding="utf-8"?>
<com.l.mapprototype.view.ToolbarLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<android.support.v7.widget.Toolbar
android:id="@+id/general_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ffffffff"
android:minHeight="?attr/actionBarSize"
android:visibility="visible" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="60dp" >
<com.l.mapprototype.view.IconView
android:id="@+id/general_toolbar_left_logo"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:visibility="gone"
tools:ignore="RtlHardcoded" />
<ImageView
android:id="@+id/general_toolbar_title_icon"
android:layout_width="wrap_content"
android:layout_height="60dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:padding="10dp"
android:src="@drawable/company_title_icon"
tools:ignore="ContentDescription" />
<com.l.mapprototype.font.RobotoTextView
android:id="@+id/general_toolbar_title"
style="@style/TextViewAppearance.Headline1"
android:layout_width="wrap_content"
android:layout_height="60dp"
android:layout_centerVertical="true"
android:layout_gravity="center"
android:layout_toRightOf="@+id/general_toolbar_left_logo"
android:gravity="center_vertical|center_horizontal"
android:padding="10dp"
android:visibility="gone" />
</RelativeLayout>
</android.support.v7.widget.Toolbar>
</com.l.mapprototype.view.ToolbarLayout>