请在回答前完整阅读问题!
假设我有两个观点:
>首先(黄色)在底部
>秒(青色)首先填充上面的其余视图
父视图的大小是动态的.
当父高度动态设置为第一列中的值时,如何实现以下预期列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"
/>