我只想在屏幕上显示两个textview,一个在另一个的上面。
TextView B: 400dp高,在底部,TextView A:填满剩余的屏幕
然而,如果textviewa的高度小于100dp,它不应该被显示(只有textviewa可见,其余的只是空白)。
这可以仅仅通过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>
如果您打算在其他几个布局中使用此特性,我会考虑将其构建到自定义视图中,您可以在其中添加一个额外的属性customer:minSize=100dp。在那个自定义视图中,你可以添加Marko的建议(即textview)。getHeight> customer:minSize then textview.setVisibility(View.Gone/Invisible)
http://developer.android.com/training/custom-views/index.htmlhttp://developer.android.com/guide/topics/ui/custom-components.html…http://mobile.tutsplus.com/tutorials/android/android-sdk-creating-custom-views-2/
否则,我就在你的活动中实现它。