我想在屏幕上显示只有两个TextViews,一个在另一个之上。Android设备上查看:隐藏,如果layout_height太小
的TextView B:400dp高,在底部, TextView的一个:填充屏幕的其余部分。但是,如果TextView A的高度小于100dp,则不应显示它(仅TextView A可见,其余仅为空白)。
可这只是XML来实现?
目前我使用这样的事情:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@color/blue"
android:text="Image A"
android:gravity="center"
android:textSize="40sp" />
<TextView
android:layout_width="fill_parent"
android:layout_height="400dp"
android:background="@color/green"
android:text="Image B: 400dp"
android:gravity="center"
android:textSize="40sp" />
</LinearLayout>
例子:
http://imageupper.com/i/?S0200010070011K1366827293817642
http://imageupper.com/i/?S0200010070021K1366827293817642
的代码,如果textviewb.getHeight <100然后textviewb.setVisibility(View.Gone)你可以做。 – 2013-04-24 14:58:00
如何您的视图B之前小于100dp,如果你想将它设置为400dp并用视图A填充剩余的空间?可能是一个错字?而且你将不得不d o一些检查代码来实现这个 – 2013-04-24 15:01:56
我认为你想'android:maxHeight =“400dp”'而不是'android:layout_height =“400dp”'因为这会使你的TExtView总是400dp,所以你永远不会少于100.然后以编程方式填充TextView,然后按照MarkoNiciforovic的建议。 – TronicZomB 2013-04-24 15:13:04