2013-07-08 3 views
0

У меня возникли проблемы с настройкой некоторых объектов в представлении.Использование Android ScrollView и ImageView за пределами

У меня есть 2 EditText и 2 Button, один под другим. И внизу экрана у меня есть ImageView, что я хочу остаться там без прокрутки.

Проблема

У меня есть ScrollView со всеми объектами внутри кроме ImageView, но последний Button не показали, потому что изображение покрывает его.

Редактировать

Мой код:

<RelativeLayout 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=".MainActivity" > 

<!-- Layout with Image set at the top of the view, outside ScrollView --> 
<LinearLayout 
    android:id="@+id/linearLayoutLogoFactor_main" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:gravity="center_horizontal" > 

    <ImageView 
     android:id="@+id/imageViewLogoFactor_main" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/logo"/> 

</LinearLayout> 

<ScrollView 
    android:id="@+id/scrollViewMain" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/linearLayoutLogoFactor_main" 
    android:layout_marginTop="7dp"> 

    <RelativeLayout 
     android:id="@+id/relativeLayoutMain" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:focusable="true" 
     android:focusableInTouchMode="true"> 

     <EditText 
      android:id="@+id/editTextLoginUsuario" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerHorizontal="true" 
      android:layout_alignParentTop="true" 
      android:hint="@string/login_usuario" 
      android:ems="10" 
      android:imeOptions="actionNext" 
      android:selectAllOnFocus="true" /> 

     <EditText 
      android:id="@+id/editTextLoginPassword" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerHorizontal="true" 
      android:layout_below="@+id/editTextLoginUsuario" 
      android:layout_marginTop="5dp" 
      android:hint="@string/login_password" 
      android:ems="10" 
      android:inputType="textPassword" 
      android:imeOptions="actionDone" 
      android:selectAllOnFocus="true" /> 

     <CheckBox 
      android:id="@+id/checkBoxRecordarDatos" 
      android:button="@drawable/checkbox_selector" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/editTextLoginPassword" 
      android:layout_centerHorizontal="true" 
      android:layout_marginTop="2dp" 
      android:text="@string/login_recordar" 
      android:textSize="@dimen/textSize" 
      android:onClick="setCheckBoxValue" /> 

     <LinearLayout 
      android:id="@+id/linearLayoutEntrar" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/checkBoxRecordarDatos" 
      android:gravity="center" 
      android:layout_marginTop="7dp" 
      android:weightSum="1.0"> 

      <Button 
       android:id="@+id/buttonEntrar" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="0.5" 
       android:text="@string/login_entrar" 
       android:textColor="@android:color/white" 
       android:textStyle="bold" 
       android:textSize="@dimen/textSize" 
       android:onClick="entrar" /> 

     </LinearLayout> 

     <!-- Layout and Button which are not seen correctly, it is covered --> 
     <LinearLayout 
      android:id="@+id/linearLayoutJugar" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/linearLayoutEntrar" 
      android:gravity="center" 
      android:layout_marginTop="7dp" 
      android:layout_marginBottom="30dp" 
      android:weightSum="1.0"> 

      <Button 
       android:id="@+id/buttonJugar" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="0.5" 
       android:text="@string/login_jugar" 
       android:textColor="@android:color/white" 
       android:textStyle="bold" 
       android:textSize="@dimen/textSize" 
       android:onClick="jugar" /> 

     </LinearLayout> 

    </RelativeLayout> 

</ScrollView> 

<LinearLayout 
    android:id="@+id/linearLayoutImagenInferior_main" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:gravity="center_horizontal" 
    android:layout_alignParentBottom="true" > 

    <ImageView 
     android:id="@+id/imageViewImagenInferior_main" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/la_electrica_de_las_empresas" 
     android:adjustViewBounds="true"/> 

</LinearLayout> 

Так как я могу установить его правильно для просмотра последнего Button, когда я прокручиваю до дна, не прикрываясь ImageView?

+1

использование линейной компоновки вместо относительного расположения, если поместить их в вертикальной линии – bogdan

+0

Я думаю, что ваш план и ваше заявление не соответствует. Вы сказали, что scrollView имеет все объекты внутри него, кроме изображения. Но это не относится к вашему размещенному XML. –

+0

Если я использую линейный макет, он говорит мне, что я ставил ориентацию, и я не хочу его указывать. – Lyd

ответ

0

Вы можете начать с замены Relative Layout на Linear Layout, как ребенок вашей ScrollView. Поведение Linear Layout должно препятствовать перекрытию Views.

Можете ли вы разделить весь файл макета и скриншот проблемы?

РЕДАКТИРОВАТЬ: как я и предполагал, проблема с перекрывающимися видами возникает из-за использования относительной компоновки. Заменить главный родительский узел Relative Layout со следующим:

<LinearLayout 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=".MainActivity" 
    android:orientation="vertical" > 
+0

Я поделился всем файлом макета, но у меня нет достаточной репутации для отправки изображения, извините. – Lyd

+0

См. Мое редактирование. Я попытался с этим изменением и смог избавиться от эффекта перекрытия. Можете ли вы попробовать это и отчитаться? :) Вот что я получил: http://tinyurl.com/mlhxeas – 2Dee

+0

Но я бы не хотел определять вертикальную ориентацию, потому что это приложение для мобильных устройств и планшета. Что мне делать? – Lyd

0
<RelativeLayout> 
    <ScrollView> 
     <LinearLayout> 
     //2 EditTexts, 2 Buttons... 
     </LinearLayout> 
    </ScrollView> 
    <LinearLayout> 
     <ImageView> 
     </ImageView> 
    </LinearLayout> 
</RelativeLayout> 

Попробуйте эту структуру макета ..

+0

Else u также может использовать LinearLayout вместо RelativeLayout –

0

enter image description here Вы должны использовать атрибут веса для этого требования. Разделите макет на две части (70/30), как я использовал в примере, и прокручиваю верхнюю часть. см. также прилагаемый снимок.

<?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="fill_parent" 
     android:layout_height="0dp" 
     android:layout_weight="7" > 

    </ScrollView> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="3" 
     android:background="#ffff00" > 

     <!-- ImageView here --> 

    </LinearLayout> 

</LinearLayout> 
0
The solution to your problem is to use weight attribute for this requirement. Divide layout into two parts(40:60) see example code 

<?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="fill_parent" 
     android:layout_height="0dp" 
     android:layout_weight="4" > 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="6" 
     android:background="#ffff00" > 

     <!-- Buttons and Edit Text here --> 

    </LinearLayout> 

    </ScrollView> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="6" 
     android:background="#ffff00" > 

     <!-- ImageView here --> 

    </LinearLayout> 
+0

Не хочу устанавливать какую-либо ориентацию, потому что это приложение для мобильных устройств и планшета. – Lyd

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