android布局隐藏代码,如何在没有代码的情况下隐藏Android布局xml中的部分可见视图?...

请在回答前完整阅读问题!

假设我有两个观点:

>首先(黄色)在底部

>秒(青色)首先填充上面的其余视图

父视图的大小是动态的.

当父高度动态设置为第一列中的值时,如何实现以下预期列UI?请注意部分可见视图是如何隐藏而不是裁剪的.

约束

>任何代码都不可能,我知道可以用以下方法解决问题:

second.setVisibility(second.getHeight()< SECONDS_PREFERRED_SIZE?GONE:VISIBLE)

但是我没有访问getHeight()所以解决方案必须是裸xml.

可以轻松编写仅通过RemoteViews编写UI状态的代码.

>基于以上所述,不允许自定义视图,甚至不允许库,只需基本布局管理器:

FrameLayout,LinearLayout,RelativeLayout,GridLayout

或作为最后的手段之一:

ViewFlipper,ListView,GridView,StackView或AdapterViewFlipper

> layout_width和layout_height是动态的

在示例中,我修复了它,因此很容易尝试不同的变化.上面的图像是layout_height更改为模拟我想要处理的可能性的显示值.

>我使用的是TextView,但它通常适用于任何View

>细心观察的人可能已经注意到,上述限制解决方案为Home screen app widgets with RemoteViews.

尝试

我尝试使用RelativeLayout和LinearLayout实现,但它们都表现为图片上的实际列.

的RelativeLayout

xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="64dp" (actually fill_parent, but fix it for sake of simplicity)

android:layout_height="fill_parent" (first column on picture)

android:layout_gravity="center"

android:background="#666"

tools:ignore="HardcodedText,RtlHardcoded"

>

android:id="@+id/first"

android:layout_width="wrap_content"

android:layout_height="16dp"

android:layout_alignParentBottom="true"

android:layout_alignParentRight="true"

android:background="#8ff0"

android:text="First"

/>

android:id="@+id/second"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:layout_above="@id/first"

android:background="#80ff"

android:text="Second"

android:gravity="center"

/>

的LinearLayout

xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="64dp" (actually fill_parent, but fix it for sake of simplicity)

android:layout_height="fill_parent" (first column on picture)

android:layout_gravity="center"

android:background="#666"

android:orientation="vertical"

tools:ignore="HardcodedText,RtlHardcoded"

>

android:id="@+id/second"

android:layout_width="fill_parent"

android:layout_height="0dp"

android:layout_weight="1"

android:background="#80ff"

android:text="Second"

android:gravity="center"

/>

android:id="@+id/first"

android:layout_width="wrap_content"

android:layout_height="16dp"

android:layout_gravity="right"

android:background="#8ff0"

android:text="First"

/>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值