Android的滚动型的RelativeLayout的使用按钮栏 [英] Android Scrollview in RelativeLayout with ButtonBar

查看:179
本文介绍了Android的滚动型的RelativeLayout的使用按钮栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现,几个EditTexts和标志是在底部在屏幕上显示一个按钮栏登录看法,是这样的:

I'm trying to implement a login view where several EditTexts and a logo are displayed on the screen with a ButtonBar at the bottom, something like this:

的问题是,在非常小的屏幕,尤其是当它们被侧向旋转时,整个主视图不适合在屏幕上。

The problem is that on very small screens, especially when they are rotated sideways, the entire main view doesn't fit onto the screen.

我现在有

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#234C59"  >
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:paddingTop="5dip"
        android:paddingLeft="15dip"
        android:paddingRight="15dip"
        android:orientation="vertical" >
        <ImageView
            android:id="@+id/logo"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:scaleType="fitCenter"
            android:layout_centerHorizontal="true"
            android:src="@drawable/logo" />
        <EditText
            android:id="@+id/input_email"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dip"
            android:inputType="textEmailAddress"
            android:singleLine="true"
            android:hint="Username or email" />
        <EditText
            android:id="@+id/input_password"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop=""
            android:inputType="textPassword"
            android:singleLine="true"
            android:hint="Password" />
    </LinearLayout>
    <LinearLayout
        android:id="@+id/buttonbar_login"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:orientation="horizontal"
        style="@android:style/ButtonBar" >
        <Button
            android:id="@+id/button_signup"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Sign Up" />
        <Button
            android:id="@+id/button_login"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Log In" />
    </LinearLayout>
</RelativeLayout>

我已经试过了滚动型看起来像这样封装第一LinnearLayout:

I've tried encapsulating the first LinnearLayout in a ScrollView that looks like this:

<ScrollView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
            <!-- Linear Layout Here -->
</ScrollView>

但是,引入了两个问题:

But that introduces two problems:

  1. 滚动视图不会在数据不滚动,甚至在屏幕上的所有合适

  1. The ScrollView doesn't scroll, even on screens where the data doesn't all fit

的按钮栏浮动在屏幕键盘的顶部,当键盘出现模糊,甚至更多的画面。

The ButtonBar floats on top of the onscreen keyboard, obscuring even more of the screen when the keyboard comes up.

一切工作伟大的,当我有滚动型里面的按钮,但现在,我有他们在的按钮栏,我有很多的麻烦搞清楚了这一点。

Everything worked great when I had the buttons inside the ScrollView, but now that I have them in the ButtonBar I'm having a lot of trouble figuring this out.

推荐答案

原来,该解决方案需要两个步骤:

It turned out that the solution required two steps:

  1. 滚动无力是的滚动型作为按钮栏后面的结果。为了解决这个问题,我下面定义的按钮栏的滚动型,然后用安卓layout_above =@ ID / buttonbar_login强制滚动型居住完全上面的按钮栏。

  1. The inability to scroll was a result of the ScrollView being behind the Button Bar. To fix this, I defined the ScrollView below the Button Bar, then used android:layout_above="@id/buttonbar_login" to force the ScrollView to reside entirely above the Button Bar.

显然,屏幕键盘打开时,如果你有一个滚动型将被调整,允许按钮栏浮动与键盘。为了解决这个问题我修改清单,并添加机器人:windowSoftInputMode =adjustPan,以prevent调整大小的滚动型

Apparently when the onscreen keyboard is opened, if you have a ScrollView it will be resized allowing the Button Bar to float up with the keyboard. To fix this I modified the manifest and added android:windowSoftInputMode="adjustPan" to prevent the ScrollView from resizing.

这篇关于Android的滚动型的RelativeLayout的使用按钮栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆