Android在外部使用ScrollView和ImageView

Android在外部使用ScrollView和ImageView,android,button,imageview,android-edittext,scrollview,Android,Button,Imageview,Android Edittext,Scrollview,我在视图中设置某些对象时遇到一些问题 我有两个编辑文本和两个按钮,一个在另一个下面。在屏幕底部,我有一个ImageView,我希望它不会被滚动 问题 我有一个滚动视图,除了图像视图,所有对象都在其中,但最后一个按钮没有显示,因为图像覆盖了它 编辑 我的代码是: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/t

我在视图中设置某些对象时遇到一些问题

我有两个
编辑文本
和两个
按钮
,一个在另一个下面。在屏幕底部,我有一个
ImageView
,我希望它不会被滚动

问题

我有一个
滚动视图
,除了
图像视图
,所有对象都在其中,但最后一个
按钮
没有显示,因为图像覆盖了它

编辑

我的代码是:

<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>

因此,当我滚动到底部时,如何正确设置它以查看最后一个
按钮,而不被
ImageView
覆盖?


<RelativeLayout>
   <ScrollView>
      <LinearLayout>
       //2 EditTexts, 2 Buttons...
      </LinearLayout>
   </ScrollView>
   <LinearLayout>
      <ImageView>
      </ImageView>
   </LinearLayout>
</RelativeLayout>
//2个编辑文本,2个按钮。。。

尝试此布局结构。

您可以首先将相对布局替换为线性布局,作为滚动视图的子级。线性布局行为应防止视图重叠

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

编辑:正如我所怀疑的,您的重叠视图问题来自于您对相对布局的使用。将主父节点相对布局替换为以下内容:

<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" >

您需要为此需求使用权重属性。按照我在示例中使用的方法,将布局分成两部分(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>

问题的解决方案是使用此需求的权重属性。将布局分成两部分(40:60),参见示例代码

如果将它们放在垂直线上,请使用线性布局而不是相对布局。我认为您的布局和您的声明不匹配。你说scrollView里面有除了图像视图以外的所有对象。但在您发布的XML中并非如此。如果我使用线性布局,它会告诉我放置方向,我不想指定方向。否则,您也可以使用线性布局而不是相对布局。我共享了我的整个布局文件,但我在提交图像方面没有足够的声誉,对不起。请查看我的编辑。我尝试了这个改变,并且能够消除重叠效应。你能试试这个然后报告吗?:)我得到的是:但我不想定义垂直方向,因为它是一款适用于手机和平板电脑的应用程序。我该怎么办?使用垂直方向不会阻止你的应用程序在横向模式或平板电脑中使用,我相信这是你想要达到的效果的最佳选择;)这意味着线性布局会将第二个子元素放在第一个子元素下面,而不是放在右边。这适用于纵向或横向屏幕。还有一件事:我在横向模式下做了一些测试,ScrollView可能包含太多元素,在小屏幕上横向显示时,最后一部分无法正确显示。您可能希望在“linearLayoutLogoFactor\u main”/“scrollViewMain”/“LinearLayoutImageInFerror\u main”上使用布局权重技巧,或者更好地为横向模式编写另一个布局。享受;)不想设置任何方向,因为它是一款适用于手机和平板电脑的应用程序。
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>