#android
Вопрос:
Я просмотрел все другие ответы, и большинство из них не использовались wrap_content
для ребенка LinearLayout
, но мой случай другой:
lt;?xml version="1.0" encoding="utf-8"?gt; lt;!--lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"--gt; lt;!-- xmlns:tools="http://schemas.android.com/tools"--gt; lt;!-- android:layout_width="match_parent"--gt; lt;!-- android:layout_height="wrap_content"--gt; lt;!-- android:orientation="vertical"--gt; lt;!-- android:gravity="center"--gt; lt;!-- tools:context=".MainActivity"gt;--gt; lt;ScrollView android:id="@ id/Scroll" android:fillViewport="true" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:gravity="center" tools:context=".MainActivity"gt; lt;LinearLayout android:id="@ id/LL2" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"gt; lt;TextView android:id="@ id/TV1" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="15dp" android:text="Test" android:clickable="false" android:textSize="20sp"/gt; lt;TextView android:id="@ id/link" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="15dp" android:text="Loading..." /gt; lt;TextView android:id="@ id/TV2" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="15dp" android:text="Test" android:textSize="20sp"/gt; lt;TextView android:id="@ id/TV3" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="15dp" android:text="Test" android:textSize="20sp"/gt; lt;TextView android:id="@ id/TV4" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="15dp" android:text="Earnings:" android:textSize="20sp"/gt; lt;TextView android:id="@ id/User_earnings" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="15dp" android:text="Loading..." android:textSize="20sp"/gt; lt;TextView android:id="@ id/TV6" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="15dp" android:text="Test" android:textSize="20sp"/gt; lt;Button android:id="@ id/btnLogOut" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_margin="15dp" android:text="Logout"/gt; lt;/LinearLayoutgt; lt;/ScrollViewgt; lt;!--lt;/LinearLayoutgt;--gt;
Редактировать:
Код не помещается на экране в ландшафтном режиме, поэтому для этого я использую вид прокрутки. Основываясь на глубокомысленных комментариях и ответах, упомянутых ниже, я внес следующие изменения в код:
- Установиться
android:layout_height="match_parent"
ScrollView
. - Установите
android:layout_height="wrap_content"
в самом первомLinearLayout
. - Добавлены идентификаторы для
ScrollView
иLinearLayout
. - Добавлено
android:fillViewport="true"
ScrollView
. - Сделал
ScrollView
родительский вид.
К сожалению , проблема все еще сохраняется.
Комментарии:
1. Установите layout_height в представлении прокрутки на «Сопоставление».
2. Привет @AleksG , я зашел
android:layout_height="match_parent"
,ScrollView
но проблема не устранена.3. установите для первой высоты линейного отображения значение wrap_content. android:layout_height=»сопоставление» с android:layout_height=»wrap_content»
Ответ №1:
Я предлагаю вам не устанавливать android:id=»@ id/ViewID» как для Linearlayout, так и для ScrollView в вашем xml-коде.
Комментарии:
1. Я попробовал это сделать , но все равно ничего не вышло.
2. Вы используете Android studio?
3. Да , я использую IntelliJ Ultimate.
Ответ №2:
Пожалуйста, проверьте свой макет, добавив еще несколько текстовых просмотров. Данный xml-код может поместиться на экране и поэтому не прокручивается.
Комментарии:
1. Код не подходит для ландшафтного режима , поэтому я пытаюсь использовать вид прокрутки.
2.Попробуйте добавить
android:fillViewport="true"
в свой scrollview или сделать свой scrollview в качестве родительского тега, напримерlt;Scrollviewgt;
lt;LinearLayoutgt;
**everything else**
lt;/LinearLayoutgt;
lt;/Scrollviewgt;
3. Спасибо за предложение! , я попробовал и то, и другое. Это не сработало.