在Android Studio中隐藏使用子视图的卡片视图
问题描述:
我目前正在使用android studio来显示实时数据。在Android Studio中隐藏使用子视图的卡片视图
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="190dp"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<WebView
android:id="@+id/webviewCO2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="CO2"
android:textAppearance="@style/TextAppearance.AppCompat.Title"
android:textColor="@color/background_floating_material_dark"
android:layout_marginTop="5dp"
android:layout_marginLeft="5dp" />
<TextView
android:id="@+id/CO2_ti"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:text="-"
android:textSize="40dp"
android:textAlignment="center"
android:layout_marginTop="5dp" />
</LinearLayout>
</android.support.v7.widget.CardView>
这是我的仪表板的组件之一。但是,有些设备没有CO2传感器,我想在这种情况下将其完全隐藏在视图中。
当我有webview时,是否有某种代码来获取“父元素”,就像在html中一样,以便我可以将CardView的可见性设置为GONE?
我现在能得到这样
WebView webViewCO2;
webViewCO2 = (WebView) view.findViewById(R.id.webviewCO2);
web视图是否有类似的财产以后我cuold做的就是cardView,这样我可以改变它的知名度? (也许如果我给cardView一个id?)
答
CardView cardView = (CardView) view.findViewById(R.id.cv_id);
和
cardView.setVisibility(View.GONE)
的伎俩