具有可见性的android布局GONE [英] android layout with visibility GONE

查看:33
本文介绍了具有可见性的android布局GONE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

四个视图使用相同的 xml.我只想显示 view 1 的线性布局.我把 android:visibility="gone" 放在 xml 中.然后我对 view 1-

Four views are using same xml. I want to show a linear layout for view 1 only. I put android:visibility="gone" in xml. And then I am doing the following for view 1-

LinearLayout layone= (LinearLayout) view.findViewById(R.id.layone);

layone.setVisibility(View.VISIBLE);

但这并没有将可见性设置为可见.

But that doesn't set the visibility to visible.

一旦在xml中声明了GONE,就不能显示视图吗?

Isn't it possible to show the view once its declared GONE in xml ?

我不想仅仅通过做来改变逻辑,

I don't want to converse the logic by just doing,

layone.setVisibility(View.GONE);

在除视图 1 之外的三个视图中的每一个中.

in each of the three views except view 1.

想法或意见?

更新:

我的 xml -

<TextView
                android:id="@+id/layone"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Previous Page"
                android:textColor="#000000"
                android:textSize="16dp"
                android:paddingLeft="10dp"
                android:layout_marginTop="10dp"
                android:visibility="gone" />
         <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="50dp"
            android:orientation="horizontal"
            android:padding="10dp"
            android:gravity="center_vertical"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"          
            android:tag="PrevEntries"     
            android:id="@+id/laytwo"
            android:layout_marginTop="10dp"
            android:background="@layout/roundedtext"
            android:visibility="gone" >

            <TextView
                android:id="@+id/laythree"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="Previous Page"
                android:textColor="#000000"
                android:textSize="18dp"
                android:gravity="center"
                android:textStyle="bold" />

        </LinearLayout>

推荐答案

这样做就完成了:

view = inflater.inflate(R.layout.entry_detail, container, false);
TextView tp1= (TextView) view.findViewById(R.id.tp1);
LinearLayout layone= (LinearLayout) view.findViewById(R.id.layone);
tp1.setVisibility(View.VISIBLE);
layone.setVisibility(View.VISIBLE);

这篇关于具有可见性的android布局GONE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆