Hel*_*rld 5 android android-layout android-linearlayout android-layout-weight
我只想在屏幕上显示两个TextView,一个在另一个之上。
TextView B:高400dp,在底部,TextView A:填充屏幕的其余部分。
但是,如果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>
Run Code Online (Sandbox Code Playgroud)
如果您打算在其他几个布局中使用此功能,我会考虑将其构建到自定义视图中,您可以在其中添加额外的属性 customer:minSize=100dp。在该自定义视图中,您可能可以添加 Marko 的建议(即 textview.getHeight > customer:minSize 然后 textview.setVisibility(View.Gone/Invisible)
http://developer.android.com/training/custom-views/index.html http://developer.android.com/guide/topics/ui/custom-components.html ... http://mobile.tutsplus .com/tutorials/android/android-sdk-creating-custom-views-2/
否则,我只会在您的活动中实现它。
| 归档时间: |
|
| 查看次数: |
1317 次 |
| 最近记录: |