2013-07-08 22 views
0

我在设置视图中的某些对象时遇到了一些问题。Android使用ScrollView和ImageView以外

我有2 EditText和2 Button,一个在另一个下面。而在屏幕的底部,我有一个ImageView,我想呆在那里没有滚动。

问题

我有里面除了ImageView的所有对象的ScrollView,但最后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

您可以通过一个线性布局取代了相对布局,为您的滚动型的孩子开始。线性布局行为应该防止视图重叠。

你能分享你的整个布局文件和问题的截图吗?

编辑:正如我怀疑,您的重叠视图问题来自您使用相对布局。用下面的更换主父节点相对布局:

<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

否则你也可以使用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