gpt4 book ai didi

java - android隐藏内部RelativeLayout防止 Activity 出现

转载 作者:行者123 更新时间:2023-12-01 14:36:43 26 4
gpt4 key购买 nike

我有一个带有内部RelativeLayouts的RelativeLayout,

我需要根据某些逻辑隐藏其中的一些RelativeLayouts,

问题是,如果我隐藏任何内部的RelativeLayouts, Activity 就不会出现,

我有checked this page做我正在做的事情,但我的不起作用??

这是我的代码,

Activity 的 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,永远不会被调用,甚至看不到 Activity 的内部日志?

隐藏我的内部布局缺少什么?

谢谢!

最佳答案

您尚未定义按钮的layout_width 和layout_height。检查 logcat 应该会给出某种错误。当您为按钮提供宽度和高度并提供一些要在按钮上显示的文本或图像时,此代码将起作用。您可以通过以下方式做到这一点

android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/warningBtnText"

关于java - android隐藏内部RelativeLayout防止 Activity 出现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16432361/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com