我的要求是我需要显示一些需要在底部显示的事件的信息。我创建了一个布局,当该事件发生时,我使用以下方法:
XML 布局
<RelativeLayout android:id="@+id/maincontainer"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
android:paddingLeft="@dimen/activity_horizontal_margin"
tools:context=".HomeActivity"
>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="BB"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="AA"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:orientation="horizontal"
android:weightSum="1">
<Button
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginRight="5dp"
android:layout_weight="0.5"
android:text="PP"/>
<Button
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginLeft="5dp"
android:layout_weight="0.5"
android:text="GG"/>
</LinearLayout>
</RelativeLayout>
显示底视图的代码:
// To check main container where new view is to be added
android.view.ViewGroup insertPoint = (android.view.ViewGroup) findViewById(R.id.maincontainer);
// New View that needs to be added
android.view.LayoutInflater vi = (android.view.LayoutInflater) getApplicationContext().getSystemService(android.content.Context.LAYOUT_INFLATER_SERVICE);
android.view.View v = vi.inflate(R.layout.app_flow_error, null);
android.widget.TextView textView = (android.widget.TextView) v.findViewById(cR.id.information_message);
textView.setText("Showing error");
//Defining the params value for new view that needs to be added
android.widget.RelativeLayout.LayoutParams layoutParams = new android.widget.RelativeLayout.LayoutParams(android.view.ViewGroup.LayoutParams.MATCH_PARENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
layoutParams.addRule(android.widget.RelativeLayout.ALIGN_PARENT_BOTTOM);
insertPoint.addView(v, insertPoint.getChildCount()-1, layoutParams);
v.setHovered(true);
需要在底部显示的视图,完全占据底部屏幕,但按钮“BB”显示出来。
您能否让我知道我实际上在做什么错,以便在底部添加新视图时按钮“BB”应该隐藏?