Android ScrollView и кнопки внизу экрана
Я хочу реализовать это: ScrollView, который содержит много элементов (ImageViews, TextViews, EditTexts и т.д.), а затем после ScrollView некоторые кнопки (которые являются настраиваемыми ImageViews), которые всегда отображаются точно в нижней части экрана.
Если я использую атрибут android: fillViewport = "true", то если элементы ScrollView слишком велики, чтобы соответствовать размеру экрана, кнопки становятся невидимыми. Если я использую атрибут android: Weight = 1, тогда ScrollView получает только 50% экрана, когда экран большой, и он может поместиться (я хочу, чтобы кнопки занимали небольшой процент, около 10%). Если я установил значение android: Weight для больших значений, кнопки будут очень маленькими.
Пожалуйста, помогите! Может быть, это что-то простое, что я забыл, но я бил головой часами!
Ответы
Ответ 1
Просто создал и протестировал это. Похоже, вы хотите.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/buttons"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center"
android:layout_alignParentBottom="true">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Custom Button1"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Custom Button2"/>
</LinearLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@id/buttons">
<!--Scrollable content here-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="test text"
android:textSize="40dp"/>
</LinearLayout>
</ScrollView>
</RelativeLayout>
Ответ 2
<?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:orientation="vertical">
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hallo Welt"
/>
</LinearLayout>
</ScrollView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Go next page"
android:layout_alignParentRight="true" />
</RelativeLayout>
</LinearLayout>
Ответ 3
Это сработало для меня. Дайте свитке просмотреть вес 1. Поместите все остальные виджеты, следующие за прокруткой в макете. Вид прокрутки будет расти настолько, чтобы не блокировать остальные.
Виджеты в виде прокрутки и отдыха внизу
Ответ 4
scrollview не может соответствовать экрану, потому что вы помещаете его в линейную компоновку, поэтому линейный макет подходит для экрана,
просто попробуйте сделать scrollview как root elemen на макете xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<!-- Here you can put some XML stuff and BOOM! your screen fit to scrollview -->
</LinearLayout>
</ScrollView>
Ответ 5
Если вы не хотите использовать RelativeLayout, лучше использовать LinearLayout. Этот метод лучше, на мой взгляд.
Просто установите layout_weight на один
![enter image description here]()