2013-08-16 4 views
0

У меня есть следующий код:Android Настройка Scrollview с относительной макете

<TextView 
     android:id="@+id/textView3" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignLeft="@+id/textView2" 
     android:layout_below="@+id/editText1" 
     android:layout_marginTop="30dp" 
     android:text="@string/cm_diameter" 
     android:textAppearance="?android:attr/textAppearanceSmall" /> 

    <TextView 
     android:id="@+id/textView4" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignLeft="@+id/textView3" 
     android:layout_below="@+id/textView3" 
     android:layout_marginTop="28dp" 
     android:text="@string/from" 
     android:textAppearance="?android:attr/textAppearanceSmall" /> 

Параметры, которые я использую связаны с относительным макете.

Я хочу обернуть это текстовое представление (у меня есть и другие виды), используя прокрутку.

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

Я попытался использовать макет лайнера в виде прокрутки, но он имеет другой результат, который я ожидал.

enter image description here

+3

+1000 Хороший фон. –

+0

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

+0

@ user2145222 Спасибо. Черная область не прокручивается с помощью прокрутки. Черная область находится под видом прокрутки. –

ответ

3

Я не знаю, что именно Android: layout_marginTop вы положили в Но как ваш дизайн выше я пытаюсь сделать простой макет для этого, и я. думаю, что это работает.

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

<ScrollView 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight="1" 
    android:background="#ff00ff00" > 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" 
     android:padding="10dip" > 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Calculation" /> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:paddingLeft="30dip" 
      android:text="Item1" 
      android:textAppearance="@android:style/TextAppearance.Large" /> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginBottom="30dip" 
      android:text="Another text view for test" 
      android:textAppearance="@android:style/TextAppearance.Large" /> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginBottom="60dip" 
      android:text="Another text view for test" 
      android:textAppearance="@android:style/TextAppearance.Large" /> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginBottom="60dip" 
      android:text="Another text view for test" 
      android:textAppearance="@android:style/TextAppearance.Large" /> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginBottom="60dip" 
      android:text="Another text view for test" 
      android:textAppearance="@android:style/TextAppearance.Large" /> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginBottom="60dip" 
      android:text="Another text view for test" 
      android:textAppearance="@android:style/TextAppearance.Large" /> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginBottom="60dip" 
      android:text="Another text view for test" 
      android:textAppearance="@android:style/TextAppearance.Large" /> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginBottom="60dip" 
      android:text="Another text view for test" 
      android:textAppearance="@android:style/TextAppearance.Large" /> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginBottom="60dip" 
      android:text="Another text view for test" 
      android:textAppearance="@android:style/TextAppearance.Large" /> 
    </LinearLayout> 
</ScrollView> 

<FrameLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="#ff000000" 
    android:padding="20dip" > 

    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:text="Add parameter" /> 
</FrameLayout> 

Правильно ли это?

+0

И если вы хотите иметь другое пространство для первого представления, используя marginTop. вы должны вы не использовать в родительском LinearLayout – hieuxit

+0

Очень хорошо...!!! –

0

Надеюсь, этот пример поможет вам начать работу, если я правильно вас понял. (Извиняюсь, если у меня нет.)

<?xml version="1.0" encoding="utf-8"?> 
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="#ff00ff00" 
> 
<ScrollView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fillViewport="true" 
    android:layout_above="@+id/footer" > 
    <LinearLayout 
     android:id="@+id/mainbody" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"    
     android:orientation="vertical"   
     >   
     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:text="Calculation"/> 
     <!--Add the rest of you views here possibly changing 'mainbody' 
     to be a RelativeLayout depending on the rest of your layout-->   
    </LinearLayout> 
</ScrollView>  
<RelativeLayout 
    android:id="@+id/footer" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    android:background="#ff000000" 
    android:layout_alignParentBottom="true"> 
    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="My footer button" 
     android:layout_margin="10dip" 
     android:layout_centerInParent="true"/> 
</RelativeLayout>  

+0

спасибо за ответ, но, как я думаю, эти параметры из моего кода не будут работать. Я имею в виду о android: layout_marginTop = «30dp» и т. Д. –

+0

@ Матросов Александр. Я смущен, добавив строку «android: layout_marginTop =« 30dp »'в linearlayout с именем« mainbody »отлично работает. Вы также можете добавить его в scrollview, если хотите, так как он находится в относительном макете в моем примере. – Matt

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