我的 LinearLayout
中有一个 TextView
和一个 Image
如果电话值通过 Intent 传递给 Activity ,那么我将包含文本和图像的布局的可见性设置为可见。
在我的代码中,布局显示,但文本和图像没有显示,即使它们在使布局可见的同一检查中设置为可见。我已经添加了我的 xml 和在我的代码中设置可见性的 Java 代码。
if(extras.getString("phone") != null){
Log.d("PHONE VISIBLE", "phone made clayout visible");
contactsLayout.setVisibility(View.VISIBLE);
phoneLayout.setVisibility(View.VISIBLE);
mPhone = extras.getString("phone");
Log.d("places got phone", mPhone.toString());
phone.setText(mPhone);
}
这是我的xml代码
<LinearLayout
android:id="@+id/contactsLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
android:layout_below="@+id/summary"
android:orientation="horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/contactsLabel"
android:background="@color/gray"
android:paddingLeft="16dp"
android:text="contact"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/phoneLayout"
android:orientation="horizontal"
android:visibility="gone">
<ImageView
android:id="@+id/phoneImage"
android:src="@drawable/icon_phone"
android:layout_width="60dp"
android:layout_height="60dp"/>
<TextView
android:id="@+id/phoneNumber"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="16dp"
tools:text="phoneNumber"/>
</LinearLayout>
<LinearLayout
android:id="@+id/emailLayout"
android:paddingLeft="16dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="gone">
<ImageView
android:id="@+id/emailImage"
android:src="@drawable/icon_email"
android:layout_width="60dp"
android:layout_height="60dp" />
<TextView
android:id="@+id/email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
tools:text="email"/>
</LinearLayout>
</LinearLayout>
最佳答案
正如迈克所说
按如下方式更改 contactsLabel:
TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/contactsLabel"
android:background="@color/gray"
android:paddingLeft="16dp"
android:text="contact"/>
关于Android 设置可见性不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33075668/