0

ビューにいくつかのオブジェクトを設定する際に問題があります。

私は 2EditTextと 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ですか?

4

4 に答える 4

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>
于 2013-07-08T10:27:20.090 に答える
0

ここに画像の説明を入力この要件には、重み属性を使用する必要があります。例で使用したように、レイアウトを 2 つの部分 (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>
于 2013-07-08T09:55:01.823 に答える
0
<RelativeLayout>
   <ScrollView>
      <LinearLayout>
       //2 EditTexts, 2 Buttons...
      </LinearLayout>
   </ScrollView>
   <LinearLayout>
      <ImageView>
      </ImageView>
   </LinearLayout>
</RelativeLayout>

このレイアウト構造を試してみてください..

于 2013-07-08T09:50:44.747 に答える
0

ScrollView の子として、Relative Layout を Linear Layout に置き換えることから始めることができます。Linear Layout の動作により、View がオーバーラップするのを防ぐ必要があります。

レイアウト ファイル全体と問題のスクリーンショットを共有できますか?

編集:私が疑ったように、重複するビューの問題は、相対レイアウトの使用に起因しています。メインの親ノード 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" >
于 2013-07-08T09:51:21.577 に答える