我有一个带有内部 RelativeLayouts 的 RelativeLayout,
我需要根据一些逻辑在其中隐藏一些RelativeLayouts,
问题是,如果我隐藏任何内部的RelativeLayouts,活动不会出现,
我已经检查了这个页面,它做了我在做什么,但我的不起作用??
这是我的代码,
活动的 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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/warning_bgnd"
android:orientation="vertical" >
<Button
android:id="@+id/button_warning"
style="@style/okWarningButton"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="62dp" />
<RelativeLayout
android:id="@+id/layout_warningA"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_alignParentTop="true"
android:layout_marginTop="70dp">
<ImageView
android:id="@+id/imageViewA"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/button_warning"
android:layout_alignParentTop="true"
android:layout_marginLeft="18dp"
android:layout_marginTop="10dp"
android:src="@drawable/warning_red"
tools:ignore="ContentDescription" />
<TextView
android:id="@+id/warningTitleA"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="70dip"
android:paddingTop="0px"
android:text="@string/textarea_warning_title"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#ffffff" />
<TextView
android:id="@+id/warningMessageA"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/warningTitleA"
android:layout_marginTop="4dp"
android:paddingLeft="70dip"
android:text="@string/textarea_warning_cat_a"
android:textColor="#B5B5B5"
android:textSize="12sp" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/layout_warningB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_alignParentTop="true"
android:layout_marginTop="170dp">
<ImageView
android:id="@+id/imageViewB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/button_warning"
android:layout_alignParentTop="true"
android:layout_marginLeft="18dp"
android:layout_marginTop="10dp"
android:src="@drawable/warning_orange"
tools:ignore="ContentDescription" />
<TextView
android:id="@+id/warningTitleB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="70dip"
android:paddingTop="0px"
android:text="@string/textarea_warning_title"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#ffffff" />
<TextView
android:id="@+id/warningMessageB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/warningTitleB"
android:layout_marginTop="4dp"
android:paddingLeft="70dip"
android:text="@string/textarea_warning_cat_b"
android:textColor="#B5B5B5"
android:textSize="12sp" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/layout_warningC"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_alignParentTop="true"
android:layout_marginTop="275dp">
<ImageView
android:id="@+id/imageViewC"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/button_warning"
android:layout_alignParentTop="true"
android:layout_marginLeft="18dp"
android:layout_marginTop="10dp"
android:src="@drawable/warning_green"
tools:ignore="ContentDescription" />
<TextView
android:id="@+id/warningTitleC"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="70dip"
android:paddingTop="0px"
android:text="@string/textarea_warning_title"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#ffffff" />
<TextView
android:id="@+id/warningMessageC"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/warningTitleC"
android:layout_marginTop="4dp"
android:paddingLeft="70dip"
android:text="@string/textarea_warning_cat_c"
android:textColor="#B5B5B5"
android:textSize="12sp" />
</RelativeLayout>
</RelativeLayout>
和 java 文件中的代码
public class WarningActivity extends PrestartAbstractActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_warning);
//myWarningLayouts
RelativeLayout layoutA = (RelativeLayout)this.findViewById(R.id.layout_warningA);
RelativeLayout layoutB = (RelativeLayout)this.findViewById(R.id.layout_warningB);
RelativeLayout layoutC = (RelativeLayout)this.findViewById(R.id.layout_warningC);
//retrieve data for intent
Intent intent = getIntent();
String warningType = intent.getStringExtra("type");
Log.d("mensa", "me entro en warning ::"+warningType);
//TODO, IMAGE BUTTON!!
Button newPreStartButton = (Button) findViewById(R.id.button_warning);
newPreStartButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
restartForms();
}
}) ;
//manage warning type
int warningTypeInt = Integer.valueOf(warningType.toString());
switch (warningTypeInt) {
case 0:
Log.d("mensa", "never happens");
break;
case 1:
Log.d("mensa", "case 1");
layoutA.setVisibility(View.VISIBLE);
layoutB.setVisibility(View.INVISIBLE);
layoutC.setVisibility(View.INVISIBLE);
break;
case 2:
Log.d("mensa", "case 2");
break;
case 3:
Log.d("mensa", "case 3");
break;
case 4:
Log.d("mensa", "case 4");
break;
case 5:
Log.d("mensa", "case 5");
break;
case 6:
Log.d("mensa", "case 6");
break;
case 7:
Log.d("mensa", "case 7");
break;
default:
Log.d("mensa", "default switch");
}
}
所以,在我的测试中,如果我有案例 1,永远不会被调用,甚至看不到活动的内部日志?
隐藏我的内部布局缺少什么?
谢谢!