Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/203.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 创建类似于android版facebook应用程序的登录布局_Java_Android_Xml_Layout - Fatal编程技术网

Java 创建类似于android版facebook应用程序的登录布局

Java 创建类似于android版facebook应用程序的登录布局,java,android,xml,layout,Java,Android,Xml,Layout,我想制作一个登录活动/布局与Facebook应用程序类似的应用程序。我的意思是,当文本字段聚焦时,软键盘会将整个视图向上推,但不会挤压徽标。我尝试过android:WindowsOfInputMode=“adjustPan/adjustResize”,但这并不是我想要实现的目标 我发现了这个问题,所以也许它会让事情变得更清楚,但它并没有解决问题的办法 我也尝试过各种布局类型,但它的软键盘只会向上推集中的。请引导我 更新: <?xml version="1.0"

我想制作一个登录活动/布局与Facebook应用程序类似的应用程序。我的意思是,当文本字段聚焦时,软键盘会将整个视图向上推,但不会挤压徽标。我尝试过android:WindowsOfInputMode=“adjustPan/adjustResize”,但这并不是我想要实现的目标

我发现了这个问题,所以也许它会让事情变得更清楚,但它并没有解决问题的办法

我也尝试过各种布局类型,但它的软键盘只会向上推集中的。请引导我

更新:

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:background="#DDDDDD">
    <RelativeLayout 
        android:height="0dp"
        android:layout_weight="1"
        android:layout_height="0dp"
        android:layout_width="fill_parent"
        android:background="#ff0000">
        <ImageView
            android:layout_centerVertical="true"
            android:layout_height="fill_parent"
            android:layout_width="fill_parent"></ImageView>
    </RelativeLayout>
    <RelativeLayout 
        android:height="0dp"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:layout_width="fill_parent"
        android:background="#00ff00">
    </RelativeLayout>

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:background="#0000ff"
        android:height="0dp" >

        <Button
            android:layout_width="fill_parent"
            android:layout_height="40dp"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            android:text="Log in" 
            />

        <EditText
            android:layout_width="fill_parent"
            android:layout_height="40dp"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:padding="4dp"
            android:hint="password"
            android:inputType="textPassword" >
        </EditText>

        <EditText
            android:id="@+id/editText1"
            android:hint="login"
            android:padding="4dp"
            android:layout_width="fill_parent"
            android:layout_height="40dp"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true" ></EditText>
    </RelativeLayout>

</LinearLayout>

子布局已设置为:

android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"  // should be changed accordingly to your layout design. 
下面是该活动的Java代码(键盘向上/向下):

在键盘向上时,您需要根据键盘向上设计更改权重,在键盘向下时,需要更改回默认设置(通过xml/java设置的布局)。我已经在2.3.x及更高版本上测试了代码。
不要忘记使用android:inputType=“textFilter”登录和密码
EditText
,删除输入建议并保存一些像素。在您的活动清单中,android:WindowsOfInputMode=“adjustResize | stateHidden”<使用代码>状态隐藏,以便在加载活动时键盘不会启动。希望能有帮助。祝你好运。

他们正在使用相对布局、调整大小和android:layout\u centerVertical。基本上,它们的主布局有一个线性布局,其中有3个权重相等的相对布局。每个都设置为0dp高度,因此它们占据屏幕的三分之一。顶部的相对位置保持徽标垂直居中。中间是登录字段和按钮,一个垂直居中,另一个垂直居中。底部一个保存版权文本,与底部对齐。最终的结果是,当键盘打开时,3个相对布局的大小会调整为新屏幕的1/3。然后它们的元素在新屏幕中居中


请记住,您需要使用adjustResize窗口模式才能获得此功能,如果使用pan,它将向上移动,徽标将滚动到中心。

在Eclipse中,转到文件|新建|其他,在下面的向导中,选择Android活动,然后在下一页上,从活动列表中选择LoginActivity。这与您所说的布局完全相同,您可以将其用作框架。它使用滚动视图来实现您想要的效果。

请查看我的更新。在facebook应用程序中,包含登录字段的部分不会调整大小,但顶部和底部元素会调整大小。在我的应用程序中,字段被合并。请帮帮我。我根据您的答案编写了xml。android新手。在facebook的布局中,由于底部几乎完全是空的,你可以给它比登录字段部分小得多的权重,让它变得更大而牺牲了其他部分。你可以玩3个部分的重量,让它在你想要的地方。我也可能会使编辑文本和按钮的高度包裹内容,以节省一些像素。谢谢,玩重量解决是我所需要的。您知道如何以编程方式更改视图/布局的权重吗?知道-您需要将视图LayoutParams设置为具有权重设置的LinearLayout.LayoutParams的实例。对于Eclipse不确定,但对于Android Studio不正确。
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"  // should be changed accordingly to your layout design. 
View top, mid, bot;
    final View activityRootView = findViewById(R.id.loginLayout);
            activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(
                    new OnGlobalLayoutListener() {
                        @Override
                        public void onGlobalLayout() {
                            int heightDiff = activityRootView.getRootView()
                                    .getHeight() - activityRootView.getHeight();
                            if (heightDiff > 100) { //keyboard up
                                mid.setVisibility(View.INVISIBLE);
                                top.setLayoutParams(new TableLayout.LayoutParams(
                                        LayoutParams.MATCH_PARENT, 0, 0f));
                                bot.setLayoutParams(new TableLayout.LayoutParams(
                                        LayoutParams.MATCH_PARENT, 0, 1f));
                                
                            } else {// keyboard down
                                // v.setVisibility(View.VISIBLE);
                                mid.setVisibility(View.VISIBLE);
                                top.setLayoutParams(new TableLayout.LayoutParams(
                                        LayoutParams.MATCH_PARENT, 0, 2f));
                                bot.setLayoutParams(new TableLayout.LayoutParams(
                                        LayoutParams.MATCH_PARENT, 0, 3f));
                                
                            }
                        }
                    });