2013-11-26 2 views
2

Я не могу видеть верхнюю часть большинства просмотров в ScrollView. Я разместил scrollview в разделе Относительная компоновка. ScrollView имеет дочернюю компоновку, то есть линейную компоновку, в которой есть несколько кнопок. Проблема в том, что я не могу увидеть верхнюю часть большинства просмотров, которые присутствуют в ScrollView.Scroll View, не отображающий все виды в android

Ниже представлен код xml.

<?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" 
    android:background="#217d27" 
    android:orientation="vertical" > 

    <RelativeLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="5dp" > 

     <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:layout_centerVertical="true" 
      android:layout_marginLeft="10dp" 
      android:onClick="backPressed" 
      android:text="Back" 
      android:textColor="#000" /> 

     <TextView 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_centerVertical="true" 
      android:gravity="center" 
      android:text="Heading Text" 
      android:textColor="#fff" 
      android:textSize="20sp" /> 

     <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentRight="true" 
      android:layout_centerVertical="true" 
      android:layout_marginRight="10dp" 
      android:onClick="homeButtonClicked" 
      android:text="Home" 
      android:textColor="#000" /> 
    </RelativeLayout> 

    <ScrollView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:fadingEdge="none" 
     android:fillViewport="true" > 

     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:background="#fff" 
      android:orientation="vertical" > 

      <Button 
       android:layout_width="200dp" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:text="Button 1" 
       android:textColor="@color/black" /> 

      <Button 
       android:layout_width="200dp" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:layout_marginTop="10dp" 
       android:text="Button 2" 
       android:textColor="@color/black" /> 

      <Button 
       android:layout_width="200dp" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:layout_marginTop="10dp" 
       android:text="Button 3" 
       android:textColor="@color/black" /> 

      <Button 
       android:layout_width="200dp" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:layout_marginTop="10dp" 
       android:text="Button 4" 
       android:textColor="@color/black" /> 

      <Button 
       android:layout_width="200dp" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:layout_marginTop="10dp" 
       android:text="Button 5" 
       android:textColor="@color/black" /> 

      <Button 
       android:layout_width="200dp" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:layout_marginTop="10dp" 
       android:text="Button 6" 
       android:textColor="@color/black" /> 

      <Button 
       android:layout_width="200dp" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:layout_marginTop="10dp" 
       android:text="Button 7" 
       android:textColor="@color/black" /> 

      <Button 
       android:layout_width="200dp" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:layout_marginTop="10dp" 
       android:text="Button 8" 
       android:textColor="@color/black" /> 

      <Button 
       android:layout_width="200dp" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:layout_marginTop="10dp" 
       android:text="Button 9" 
       android:textColor="@color/black" /> 

      <Button 
       android:layout_width="200dp" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:layout_marginTop="10dp" 
       android:text="Button 10" 
       android:textColor="@color/black" /> 

      <Button 
       android:layout_width="200dp" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:layout_marginTop="10dp" 
       android:text="Button 11" 
       android:textColor="@color/black" /> 

      <Button 
       android:layout_width="200dp" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:layout_marginTop="10dp" 
       android:text="Button 12" 
       android:textColor="@color/black" /> 
     </LinearLayout> 
    </ScrollView> 

</LinearLayout> 

См. Снимок экрана для справки.

Screen shot

+0

Использование Относительное расположение вместо линейной в качестве родителя. –

+0

Nope Относительная компоновка также не работает. Я получаю тот же результат. – ravi

+0

ваш код 99% идеально подходит, просто удалите 1 строку, только увидишь мой ответ, я обновляю код чувака и приветствую всегда :) –

ответ

8

просто удалить эту строку в линейной компоновке, которая является прямым потомком зрения прокрутки андроида: layout_gravity = «центр» попробуй этот код, который обновляется

<?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" 
    android:background="#217d27" 
    android:orientation="vertical" > 

    <RelativeLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="5dp" > 

     <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:layout_centerVertical="true" 
      android:layout_marginLeft="10dp" 
      android:onClick="backPressed" 
      android:text="Back" 
      android:textColor="#000" /> 

     <TextView 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_centerVertical="true" 
      android:gravity="center" 
      android:text="Heading Text" 
      android:textColor="#fff" 
      android:textSize="20sp" /> 

     <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentRight="true" 
      android:layout_centerVertical="true" 
      android:layout_marginRight="10dp" 
      android:onClick="homeButtonClicked" 
      android:text="Home" 
      android:textColor="#000" /> 
    </RelativeLayout> 

    <ScrollView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:fadingEdge="none" 
     android:fillViewport="true" > 

     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:background="#fff" 
      android:orientation="vertical" > 

      <Button 
       android:layout_width="200dp" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:text="Button 1" 
       android:textColor="@color/black" /> 

      <Button 
       android:layout_width="200dp" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:layout_marginTop="10dp" 
       android:text="Button 2" 
       android:textColor="@color/black" /> 

      <Button 
       android:layout_width="200dp" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:layout_marginTop="10dp" 
       android:text="Button 3" 
       android:textColor="@color/black" /> 

      <Button 
       android:layout_width="200dp" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:layout_marginTop="10dp" 
       android:text="Button 4" 
       android:textColor="@color/black" /> 

      <Button 
       android:layout_width="200dp" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:layout_marginTop="10dp" 
       android:text="Button 5" 
       android:textColor="@color/black" /> 

      <Button 
       android:layout_width="200dp" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:layout_marginTop="10dp" 
       android:text="Button 6" 
       android:textColor="@color/black" /> 

      <Button 
       android:layout_width="200dp" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:layout_marginTop="10dp" 
       android:text="Button 7" 
       android:textColor="@color/black" /> 

      <Button 
       android:layout_width="200dp" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:layout_marginTop="10dp" 
       android:text="Button 8" 
       android:textColor="@color/black" /> 

      <Button 
       android:layout_width="200dp" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:layout_marginTop="10dp" 
       android:text="Button 9" 
       android:textColor="@color/black" /> 

      <Button 
       android:layout_width="200dp" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:layout_marginTop="10dp" 
       android:text="Button 10" 
       android:textColor="@color/black" /> 

      <Button 
       android:layout_width="200dp" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:layout_marginTop="10dp" 
       android:text="Button 11" 
       android:textColor="@color/black" /> 

      <Button 
       android:layout_width="200dp" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:layout_marginTop="10dp" 
       android:text="Button 12" 
       android:textColor="@color/black" /> 
     </LinearLayout> 
    </ScrollView> 

</LinearLayout> 
1

Попробуйте изменить родительское расположение к Linear. Это может сработать. Не знаю, как и почему, но для меня это работало в аналогичной ситуации. Попробуйте.

7

Просто измените LinearLayout внутри ScrollView

<LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="top|center" 
     android:background="#fff" 
     android:orientation="vertical" > 

Дайте android:layout_gravity="top|center" вместо того, чтобы android:layout_gravity="center"

H Это помогает.

+0

Спасибо, много Анудж. – ravi

+0

О, мой бог .. так много: D – Jenson

3

Этих значения помогли мне решить подобную проблему: Set андроид: fillViewport = «истинный» на ScrollView и использовать андроид: гравитацию вместо андроида: layout_gravity на ребенке Scrollview, в моем случае LinearLayout со всеми весами.

-1

использование андроида: layout_gravity = «центр» в LinearLayout

Смежные вопросы