如何让布局不是高度裁剪?例如,如果我将向上移动contentLayout,则屏幕上不适合屏幕的部分将被裁剪。 ScrollView不合适。因为我编写了一个组件并需要控制
的行为<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView">
</TextView>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView">
</TextView>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView">
</TextView>
... so many elements
</LinearLayout>
答案 0 :(得分:1)
将根布局从LinearLayout更改为ScrollView。这样,如果内容不适合屏幕,您仍然可以向下滚动一点以查看布局的底部。
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView1"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView2"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView3"/>
<!-- And your other TextViews -->
</ScrollView>
但是如果你有很多TextViews(比如20,50或更多),我的建议是使用ListView而不是单独添加每个TextView。
Here你有一个如何在Android中使用ListView的基本示例。