Нет прокрутки в scrollview - PullRequest
       0

Нет прокрутки в scrollview

3 голосов
/ 26 октября 2011

У меня проблема с прокруткой ...

мой xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="wrap_content" android:layout_height="wrap_content">

         <ScrollView android:id="@+id/scrollView1" android:layout_width="wrap_content" android:layout_height="match_parent">
             <RelativeLayout [...]>
                 <TextView [...]></TextView>
                 <Spinner [...]></Spinner>
                 <Button [...]></Button>
                 <ImageButton [...]></ImageButton>
                 <TextView [...]></TextView>
                 <TableLayout [...]>
                     <TableRow [...]>
                         <TextView [...]></TextView>
                         <TextView [...]></TextView>
                         <TextView [...]></TextView>
                     </TableRow>
                     <TableRow [...]>
                         <AutoCompleteTextView [...]></AutoCompleteTextView>
                         <AutoCompleteTextView [...]></AutoCompleteTextView>
                         <Spinner [...]></Spinner>
                     </TableRow>
                 </TableLayout>
            </RelativeLayout>
         </ScrollView>
</LinearLayout>

Когда я пытаюсь прокрутить приложение, оно не работает ... что я сделал не так? я удалил свойства из элементов. если они нужны вам для решения проблемы, я могу добавить их. я сделал это, чтобы получить лучший обзор.

спасибо, prexx

Ответы [ 4 ]

3 голосов
/ 26 октября 2011

Попробуйте добавить ScrollView в качестве родителя. Отличное место с LinearLayout. И не забудьте добавить следующее в ScrollView вместо LinearLayout:

xmlns:android="http://schemas.android.com/apk/res/android"

И layout_widht и layout_height ScrollView должны быть установлены на «fill_parent»

Это мой код, который использует ScrollView в календаре, который я сделал, может помочь вам:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true">
<LinearLayout
android:id="@+id/layout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/bg">
<LinearLayout 
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
    <Button android:id="@+id/dayView" android:text="Day" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1"/>
    <Button android:id="@+id/weekView" android:text="Week" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1"/>
    <Button android:text="Month" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:enabled="false"/>
    <Button android:id="@+id/eventsView" android:text="Events" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1"/>
</LinearLayout>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
    <ImageView
        android:id="@+id/prevMonth"
        android:src="@drawable/calendar_left_arrow_selector"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
    </ImageView>
    <Button
        android:id="@+id/currentMonth"
        android:layout_weight="0.6"
        android:textColor="#FFFFFF"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:background="@drawable/calendar_bar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
    </Button>
    <ImageView
        android:id="@+id/nextMonth"
        android:src="@drawable/calendar_right_arrow_selector"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
    </ImageView>
</LinearLayout>
<LinearLayout
    android:layout_gravity="center"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
    <TextView android:layout_width="wrap_content" android:layout_height="20dp" android:text="Week" android:textColor="#000000" android:layout_weight="1"/>
    <TextView android:id="@+id/monday" android:layout_width="wrap_content" android:layout_height="20dp" android:text="" android:textColor="#000000" android:layout_weight="1"/>
    <TextView android:id="@+id/tuesday" android:layout_width="wrap_content" android:layout_height="20dp" android:text="" android:textColor="#000000" android:layout_weight="1"/>
    <TextView android:id="@+id/wednesday" android:layout_width="wrap_content" android:layout_height="20dp" android:text="" android:textColor="#000000" android:layout_weight="1"/>
    <TextView android:id="@+id/thursday" android:layout_width="wrap_content" android:layout_height="20dp" android:text="" android:textColor="#000000" android:layout_weight="1"/>
    <TextView android:id="@+id/friday" android:layout_width="wrap_content" android:layout_height="20dp" android:text="" android:textColor="#000000" android:layout_weight="1"/>
    <TextView android:id="@+id/saturday" android:layout_width="wrap_content" android:layout_height="20dp" android:text="" android:textColor="#000000" android:layout_weight="1"/>
    <TextView android:id="@+id/sunday" android:layout_width="wrap_content" android:layout_height="20dp" android:text="" android:textColor="#000000" android:layout_weight="1"/> 
</LinearLayout>
<LinearLayout 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:layout_weight="1">
    <ViewFlipper
       android:id="@+id/flipper"
       android:layout_width="fill_parent"
       android:layout_height="fill_parent">
    <LinearLayout 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="horizontal">
        <GridView
            android:id="@+id/weeks"
            android:numColumns="1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="8"
            android:scrollbars="none">
        </GridView>
        <GridView
            android:id="@+id/calendar"
            android:numColumns="7"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:scrollbars="none">
        </GridView>
    </LinearLayout>
    <LinearLayout 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="horizontal">
        <GridView
            android:id="@+id/weeks2"
            android:numColumns="1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="8"
            android:scrollbars="none">
        </GridView>
        <GridView
            android:id="@+id/calendar2"
            android:numColumns="7"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:scrollbars="none">
        </GridView>
    </LinearLayout>
</ViewFlipper>
</LinearLayout>
<LinearLayout
        android:id="@+id/bottom_layout" 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">
        <Button
            android:id="@+id/create_event"
            android:text="Create event"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>
</ScrollView>
2 голосов
/ 26 октября 2011

Попробуйте добавить android:fillViewport="true" к вашему scrollView.

Высота вашего scrollView, вероятно, должна быть либо match_parent, либо fill_parent, а также.

0 голосов
/ 06 ноября 2012

Если контент ScrollView не занимает все пространство, он будет вести себя как обычный макет, то есть не прокручиваемый.

Если вам все еще требуется ScrollView для заполнения всего экрана (но все еще нет прокрутки, так как не хватает контента), вы можете сделать так, как упомянул Николас Магнуссен и добавить android:fillViewport="true"

0 голосов
/ 26 октября 2011

Пожалуйста, измените на android:layout_width="wrap_content" android:layout_height="wrap_content" заполнить родительский.

Спасибо

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...