ScrollView в андроид - PullRequest
       0

ScrollView в андроид

2 голосов
/ 09 июня 2010

У меня есть представление, которое содержит несколько текстовых представлений, ImageView и кнопку.Поскольку на устройствах с маленьким экраном (или в альбомном режиме на больших) не все видны, я использую Scroll в качестве родителя всей иерархии, чтобы позволить пользователю просматривать всю информацию.Дело в том, что кнопка должна быть в нижней части обзора.Однако на устройстве с большим экраном, где у основания остается достаточно места, кнопка помещается непосредственно под последним просмотром текста и, кажется, занимает все оставшееся пространство (что приводит к неактивному виду).Попытка использовать android: allignParentButtom = "true" не только потому, что это не имеет никакого эффекта, но и помещает кнопку в верхней части экрана.У кого-нибудь есть идеи, как я могу выполнить то, что я описал?

Вот XML

<?xml version="1.0" encoding="utf-8"?>
  <ScrollView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/scroll_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true">


     <RelativeLayout
         android:id="@+id/gps_info_page1"
         android:layout_width="fill_parent"
         android:layout_height="fill_parent"
         android:layout_centerHorizontal="true">

       <TextView
            android:id="@+id/itsDateTimeValue"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:text="@string/eStrUnknown">
       </TextView>

     <RelativeLayout
             android:id="@+id/directions"
             android:layout_centerHorizontal="true"
             android:layout_below="@+id/itsDateTimeValue"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content">

         <TextView
                android:id="@+id/itsDirectionValue"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="0"
                android:layout_marginRight="2dip"
                android:textSize="20sp">
        </TextView>
        <TextView
                android:id="@+id/itsOrientation"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textSize="20sp"
                android:layout_marginLeft="2dip"
                android:text="@string/eStrUnknown"
                android:layout_toRightOf="@+id/itsDirectionValue">
        </TextView>
    </RelativeLayout>



    <ImageView
        android:id="@+id/itsImage"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/compass"
        android:layout_below="@+id/directions"
        android:layout_centerHorizontal="true">
     </ImageView> 

    <RelativeLayout>
       ..."TextViews below the above image"
    </RelativeLayout> 

    <RelativeLayout>
      ..."TextViews below the above"         
    </RelativeLayout>

    <RelativeLayout>
     ..."TextViews below the above"  
    </RelativeLayout> 

    <RelativeLayout>
    ..."TextViews below the above"            
   </RelativeLayout>

   <RelativeLayout
    ..."TextViews below the above" 
  </RelativeLayout>


   <LinearLayout
      android:id="@+id/div"
      android:layout_width="fill_parent"
      android:layout_height="1dip"
      android:layout_below="@+id/sunset_layout"
      android:background="#F333">
   </LinearLayout>

   <Button  //adding here android:alignParentBottom="true" has described above behavior
     android:layout_marginBottom="3dip"
     android:layout_marginTop="20dip"
     android:id="@+id/done_button"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:text="@string/eStrDone"
     android:textSize="18sp"
     android:layout_below="@+id/div"
     android:layout_centerHorizontal="true">
    </Button> 


   </RelativeLayout>

</ScrollView>

Ответы [ 2 ]

1 голос
/ 09 июня 2010

Что вы можете сделать, это программно изменить размеры в зависимости от экрана.

С помощью этой строки вы получите плотность экрана:

scale = getResources().getDisplayMetrics().density;

, и этоэто вы получите размер:

windowManager = getWindowManager(); display = windowManager.getDefaultDisplay(); screenWidth = display.getWidth(); screenHeight = display.getHeight();

и с этим вы можете получить его на portarit или ландшафт:

Configuration conf = context.getResources().getConfiguration();

Свсю эту информацию, вы можете изменять экран по своему усмотрению.

Иногда необходимо сделать некоторые вычисления, потому что не только плотность отличается, но и размер различен (например, Nexus One и Droid)

Надеюсьэто помогает.

Даниэль

0 голосов
/ 14 февраля 2011

Вы можете поместить ваше представление прокрутки в линейную линейку и установить вес вида прокрутки как 1

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