2010-09-29 27 views

Trả lời

154

Chỉ cần quấn tất cả những gì bên trong một 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"> 
    <!-- Here you put the rest of your current view--> 
</ScrollView> 

Như David Hedlund cho biết, ScrollView có thể chỉ chứa một mục ... vì vậy nếu bạn có một cái gì đó như thế này:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <!-- bla bla bla--> 
</LinearLayout> 

Bạn phải thay đổi thành:

<?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"> 
    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 
     <!-- bla bla bla--> 
    </LinearLayout> 
</ScrollView> 
+9

+1. một lưu ý nhanh: một 'ScrollView' chỉ có thể chứa một con, vì vậy nếu những gì bạn đang có là rất nhiều khung nhìn, bạn cần phải bọc chúng trong một nhóm xem (nói một' LinearLayout') –

+1

Cảm ơn bạn @David Hedlund –

+0

cách khắc phục sự cố của tôi, vui lòng giúp tôi http://stackoverflow.com/questions/38588702/why-my-scrollview-not-working-properly – Karthi

29

Để sử dụng xem di chuyển cùng với cách bố trí tương đối:

<ScrollView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:fillViewport="true"> <!--IMPORTANT otherwise backgrnd img. will not fill the whole screen --> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:paddingBottom="@dimen/activity_vertical_margin" 
     android:paddingLeft="@dimen/activity_horizontal_margin" 
     android:paddingRight="@dimen/activity_horizontal_margin" 
     android:paddingTop="@dimen/activity_vertical_margin" 
     android:background="@drawable/background_image" 
    > 

    <!-- Bla Bla Bla i.e. Your Textviews/Buttons etc. --> 
    </RelativeLayout> 
</ScrollView> 
+0

Thẻ khung nhìn là gì –

0

Nếu bạn thậm chí không được di chuyển sau khi làm những gì được viết trên .....

Đặt android:layout_height="250dp" hoặc bạn có thể nói xdp trong đó x có thể là bất kỳ giá trị số nào.

1

Chỉ cần quấn tất cả những gì bên trong một scrollview

<?xml version="1.0" encoding="utf-8"?> 

<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" 
    tools:context="com.ruatech.sanikamal.justjava.MainActivity"> 
<!-- Here you put the rest of your current view--> 
</ScrollView> 
Các vấn đề liên quan