【问题标题】:Partial UI screen up部分 UI 屏幕向上
【发布时间】:2015-12-02 07:52:50
【问题描述】:

在屏幕上,我在顶部有一个编辑文本(大包含 4-5 行的空间),在其下方有图像视图,在底部有提交按钮。在键盘上它不应该隐藏我的提交按钮。

当键盘出现时,我可以使用android:windowSoftInputMode="adjustResize" 调整窗口大小,这样我就不会隐藏提交按钮,但它也会调整我不想要的图像大小。

只有当键盘可见而不调整图像大小时,提交按钮才应该向上移动。

我也尝试了框架布局,但它没有可能是我尝试了错误的方式。如有任何帮助,我们将不胜感激。

【问题讨论】:

    标签: android android-layout android-imageview android-relativelayout


    【解决方案1】:

    应用这个并让我知道它是否仍在发生。

    activity_mian.xml

    <ScrollView 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"
        android:layout_gravity="center_vertical|center_horizontal"
        android:background="@drawable/xxx.jpg"
        android:orientation="vertical"
        tools:context=".LoginActivity" >
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical|center_horizontal"
            android:orientation="vertical" >
    
            <ImageView
                android:id="@+id/imageView1"
                android:layout_width="match_parent"
                android:layout_height="190dp"
                android:layout_marginTop="20dp"
                android:src="@drawable/logo_app" />
    
            <EditText
                android:id="@+id/edtEmail"
                android:layout_width="wrap_content"
                android:layout_height="50dp"
                android:layout_gravity="center_vertical|center_horizontal"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp"
                android:layout_marginTop="10dp"
                android:background="@drawable/login_textbox"
                android:ems="10"
                android:hint="Email"
                android:imeOptions="actionNext"
                android:inputType="textEmailAddress"
                android:singleLine="true"
                android:textColor="#ffffff"
                android:textCursorDrawable="@null" />
    
            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content" >
    
                <EditText
                    android:id="@+id/edtPassword"
                    android:layout_width="wrap_content"
                    android:layout_height="50dp"
                    android:layout_gravity="center_vertical|center_horizontal"
                    android:layout_marginLeft="10dp"
                    android:layout_marginRight="10dp"
                    android:background="@drawable/login_textbox"
                    android:ems="10"
                    android:hint="Password"
                    android:imeOptions="actionDone"
                    android:inputType="textPassword"
                    android:singleLine="true"
                    android:textColor="#ffffff"
                    android:textCursorDrawable="@null" />
    
                <ImageView
                    android:id="@+id/imageView2"
                    android:layout_width="40dp"
                    android:layout_height="40dp"
                    android:layout_alignParentTop="true"
                    android:layout_alignRight="@+id/edtPassword"
                    android:layout_marginTop="2dp" />
            </RelativeLayout>
    
            <CheckBox
                android:id="@+id/checkBox_remember"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:layout_marginTop="20dp"
                android:button="@drawable/checkbox_selector"
                android:checked="true"
                android:focusable="false"
                android:focusableInTouchMode="true"
                android:text="  Remember Me"
                android:textColor="#ffffff" />    
    
    
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="15dp"
                android:layout_marginRight="15dp"
                android:layout_marginTop="10dp"
                android:orientation="vertical" >
    
                <Button
                    android:id="@+id/btnLogin"
                    android:layout_width="wrap_content"
                    android:layout_height="50dp"
                            android:layout_gravity="top|center_vertical|center_horizontal"
                    android:layout_marginTop="10dp"
                    android:layout_marginLeft="20dp"
                    android:layout_marginRight="20dp"
                    android:background="@drawable/btn_login" />
    
    
            </LinearLayout>
    
    
        </LinearLayout>
    
    </ScrollView>
    

    将您的 Button、EditText 等设置在一个线性布局中,然后是一个父 ScrollView。

    另一件事是设置 android:windowSoftInputMode="stateAlwaysHidden" 在你的 xml 文件绑定的 java 文件中。

    【讨论】:

    • 感谢您的解决方案,并对其进行了一些更改,因此请编辑答案。
    • 如果它为您使用完整的答案,请除外。@CodingRat
    • 1) 在我的情况下,根布局正常 相对布局。然后滚动视图内的滚动视图采用线性布局,其中指定编辑文本+图像视图。然后是底部按钮。
    • 2) android:windowSoftInputMode="adjustResize"
    • 3) 使用 mScrollView.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return true; } }) 禁用 java 代码中的滚动;
    【解决方案2】:

    随着@jigs 答案的一些变化,我得到了它的工作和发布可能可以帮助像我这样的其他人

    1) 在我的例子中,根布局与正常的相对布局一样。然后滚动视图内的滚动视图采用线性布局,其中指定编辑文本+图像视图。然后是底部按钮。

    <?xml version="1.0" encoding="utf-8"?>
    
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/root_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="?android:attr/actionBarSize"
        android:background="@android:color/white"
        android:orientation="vertical">
    
    <ScrollView
        android:id="@+id/scrollViewNotScrollable"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@id/user_name_container">
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center_vertical"
            android:orientation="vertical"
    
            >
    
            <EditText
                android:id="@+id/input_feed"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp"
                android:background="#00000000"
                android:ellipsize="start"
                android:focusable="true"
                android:focusableInTouchMode="true"
                android:gravity="start|center_vertical"
                android:hint="@string/feed_hint"
                android:imeActionLabel="Submit"
                android:imeOptions="actionSend"
           android:inputType="textMultiLine|textAutoCorrect|textCapSentences"
                android:maxLines="5"
                android:minLines="3"
                android:paddingLeft="5dp"
                android:paddingRight="5dp"
                android:paddingTop="25dp"
                android:textColor="@color/feed_sub_color"
                android:textColorHint="@color/light_gray"
                android:textCursorDrawable="@null" />
    
            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="20dp">
                <!--<ScrollView
                    android:id="@+id/scroll"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:isScrollContainer="false"
                    android:padding="4dp"
    
                    android:layout_centerHorizontal="true"
                    >-->
                <ImageView
                    android:id="@+id/imgPreview"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerHorizontal="true"
                    android:layout_gravity="center"
                    android:layout_marginBottom="20dp"
                    android:layout_marginTop="20dp"
                    android:adjustViewBounds="true"
                    android:background="@android:color/white"
                    android:elevation="5dp"
                    android:padding="4dp"
                    android:visibility="gone" />
                <!--</ScrollView>-->
                <ImageView
                    android:id="@+id/close_image"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignTop="@+id/imgPreview"
                    android:layout_marginLeft="-45dp"
                    android:layout_marginTop="-20dp"
                    android:layout_toRightOf="@+id/imgPreview"
                    android:elevation="5dp"
                    android:paddingBottom="15dp"
                    android:src="@drawable/closeimage"
                    android:visibility="gone" />
    
            </RelativeLayout>
        </LinearLayout>
    </ScrollView>
    
    <RelativeLayout
        android:id="@+id/user_name_container"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:fitsSystemWindows="true">
    
        <View
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:background="@android:color/darker_gray" />
    
        <EditText
            android:id="@+id/feed_user_name"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:background="@null"
            android:ellipsize="end"
            android:fontFamily="san-serif-condensed"
            android:padding="12dp"
            android:singleLine="true"
            android:text="sherry's phone"
            android:textColor="@android:color/black"
            android:textSize="@dimen/feed_name_size"
            android:visibility="gone" />
    
        <TextView
            android:id="@+id/feed_user_name_textView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:background="@null"
            android:ellipsize="end"
            android:fontFamily="san-serif-condensed"
            android:padding="12dp"
            android:paddingLeft="20dp"
            android:singleLine="true"
            android:text="sherry's phone"
            android:textColor="@android:color/black"
            android:textSize="@dimen/feed_name_size" />
    
        <ImageView
            android:id="@+id/edit_name"
            android:layout_width="wrap_content"
            android:layout_height="30dp"
            android:layout_alignParentRight="true"
            android:layout_gravity="end"
            android:layout_marginBottom="10dp"
            android:layout_marginRight="10dp"
            android:layout_marginTop="10dp"
            android:paddingBottom="5dp"
            android:paddingTop="5dp"
            android:scaleType="centerInside"
            android:src="@drawable/editname" />
    
        <Button
            android:id="@+id/done"
            android:layout_width="wrap_content"
            android:layout_height="30dp"
            android:layout_alignParentRight="true"
            android:layout_marginBottom="10dp"
            android:layout_marginRight="10dp"
            android:layout_marginTop="10dp"
            android:background="@drawable/rounded_corner_update_block"
            android:fontFamily="san-serif-medium"
            android:text="Done"
            android:textColor="@android:color/white"
            android:visibility="gone" />
    </RelativeLayout>
    
    </RelativeLayout>
    

    2)android:windowSoftInputMode="adjustResize" 在 manifest.xml 中

    3) 在 java 代码中禁用滚动(可选)

        mScrollView.setOnTouchListener( new OnTouchListener() {
    
                @Override
                public boolean onTouch(View v, MotionEvent event) 
                {
                      return true;
                }
    });
    

    【讨论】:

      猜你喜欢
      • 2021-12-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-14
      • 1970-01-01
      • 1970-01-01
      • 2012-09-30
      • 1970-01-01
      相关资源
      最近更新 更多