поместив кнопку над клавиатурой - PullRequest
0 голосов
/ 13 мая 2018

У меня есть код, чтобы проверить, видна ли клавиатура Softinput или нет.Но я не знаю, как установить кнопку, которая изначально находится в нижней части макета, чуть выше клавиатуры. Я установил макет на FULL SCREEN , поэтому softInputMode присвоено значение AdjustResize в Манифесте больше не будет работать. Я знаю это. Пока я просто устанавливаю позицию «Y» кнопки ( id = next ) на некоторое значение вышеКлавиатура. Но я хочу, чтобы она была чуть выше клавиатуры. Жду вашей помощи !! Заранее спасибо.

Java-код:

final Window mRootWindow=getActivity().getWindow();
        frag1Binding.relative.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                int screenheight=frag1Binding.relative.getRootView().getHeight();
                Rect r=new Rect();
                View view=mRootWindow.getDecorView();
                view.getWindowVisibleDisplayFrame(r);
                int keyboardheight=screenheight-r.bottom;
                if (keyboardheight>150){
                    lastheight=keyboardheight;
                    Log.e("EditText_Bottom",Integer.toString(frag1Binding.phnmbr.getBottom()));
                    linearLayoutParams=new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                    orginalpositon=frag1Binding.next.getY();
                    Log.e("Original Y",Float.toString(frag1Binding.next.getY()));
                    frag1Binding.next.setY(100);

                    }
            else {
                    if (lastheight>150){
                    frag1Binding.next.setY(orginalpositon);
                }}
            }
        });

XML:

<?xml version="1.0" encoding="utf-8"?>
<layout
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:android="http://schemas.android.com/apk/res/android">
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#ffffff"
        android:id="@+id/relative"
        >
        <TextView
            android:id="@+id/head"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="@dimen/ph_verify_lbl_mrgn"
            android:text="verify_your_phone_number"
            android:textColor="#bb2b67"
            android:textSize="@dimen/ph_verify_head_tsxtsze"
            />
        <TextView
            android:id="@+id/textView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/head"
            android:layout_marginLeft="8dp"
            android:layout_marginStart="8dp"
            android:layout_marginTop="4dp"
            android:text="lorem_ipsum_lorem_ipsum"
            />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="60dp"
            android:text="+91"
            android:layout_below="@+id/textView"
            android:gravity="center|bottom"
            android:id="@+id/countrycode"
            android:textSize="@dimen/ph_verify_head_tsxtsze"
            android:textColor="#000000"
            android:layout_marginTop="8dp"
            android:layout_marginLeft="8dp"
            android:layout_marginStart="8dp"
            android:layout_marginBottom="8dp"
            />
        <EditText
            android:layout_width="312dp"
            android:layout_height="60dp"
            android:id="@+id/phnmbr"
            android:layout_toRightOf="@+id/countrycode"
            android:layout_below="@+id/textView"
            android:background="@drawable/edittext_bg"
            android:hint="Hint"
            android:inputType="number"
            android:gravity="start|center|bottom"
            android:paddingLeft="20dp"
            android:layout_marginRight="8dp"
            android:layout_marginEnd="8dp"
            android:layout_marginLeft="10dp"
            android:layout_marginStart="10dp"
            android:focusable="true"
            android:fitsSystemWindows="true"
            android:focusableInTouchMode="true"
            android:freezesText="true"
            android:layout_marginTop="8dp"
            android:layout_marginBottom="8dp"
            />


        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"

            android:layout_below="@+id/phnmbr"
            android:layout_alignParentBottom="true"
            >

            <Button
                android:id="@+id/next"
                android:layout_width="match_parent"
                android:layout_height="65dp"

                android:layout_alignParentBottom="true"
                android:background="@drawable/button_bg"
                android:text="NEXT"
                android:textColor="#ffffff"
                android:textSize="22sp">

            </Button>
            <ImageView
                android:id="@+id/imageView"
                android:layout_width="20dp"
                android:layout_height="25dp"
                android:elevation="2dp"
                android:layout_alignParentEnd="true"
                android:layout_alignParentBottom="true"
                android:layout_marginBottom="18dp"
                android:layout_marginEnd="19dp"
                android:background="@drawable/arrow"
                android:layout_alignParentRight="true"
                android:layout_marginRight="19dp"/>
        </RelativeLayout>
    </RelativeLayout>
</layout>

1 Ответ

0 голосов
/ 13 мая 2018

Вам было тяжело.

Все просто, вам не нужно писать код Java для обработки этого поведения.оберните ваш контент ScrollView и удерживайте кнопку вне ScrollView, которой вы хотите быть выше.

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">


        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1">


            <RelativeLayout
                android:id="@+id/relative"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="#ffffff">

                <TextView
                    android:id="@+id/head"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_margin="@dimen/ph_verify_lbl_mrgn"
                    android:text="verify_your_phone_number"
                    android:textColor="#bb2b67"
                    android:textSize="@dimen/ph_verify_head_tsxtsze" />

                <TextView
                    android:id="@+id/textView"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/head"
                    android:layout_marginLeft="8dp"
                    android:layout_marginStart="8dp"
                    android:layout_marginTop="4dp"
                    android:text="lorem_ipsum_lorem_ipsum" />

                <TextView
                    android:id="@+id/countrycode"
                    android:layout_width="wrap_content"
                    android:layout_height="60dp"
                    android:layout_below="@+id/textView"
                    android:layout_marginBottom="8dp"
                    android:layout_marginLeft="8dp"
                    android:layout_marginStart="8dp"
                    android:layout_marginTop="8dp"
                    android:gravity="center|bottom"
                    android:text="+91"
                    android:textColor="#000000"
                    android:textSize="@dimen/ph_verify_head_tsxtsze" />

                <EditText
                    android:id="@+id/phnmbr"
                    android:layout_width="312dp"
                    android:layout_height="60dp"
                    android:layout_below="@+id/textView"
                    android:layout_marginBottom="8dp"
                    android:layout_marginEnd="8dp"
                    android:layout_marginLeft="10dp"
                    android:layout_marginRight="8dp"
                    android:layout_marginStart="10dp"
                    android:layout_marginTop="8dp"
                    android:layout_toRightOf="@+id/countrycode"
                    android:background="@drawable/edittext_bg"
                    android:fitsSystemWindows="true"
                    android:focusable="true"
                    android:focusableInTouchMode="true"
                    android:freezesText="true"
                    android:gravity="start|center|bottom"
                    android:hint="Hint"
                    android:inputType="number"
                    android:paddingLeft="20dp" />


            </RelativeLayout>
        </ScrollView>

        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <Button
                android:id="@+id/next"
                android:layout_width="match_parent"
                android:layout_height="65dp"
                android:background="@drawable/button_bg"
                android:text="NEXT"
                android:textColor="#ffffff"
                android:textSize="22sp">

            </Button>

            <ImageView
                android:id="@+id/imageView"
                android:layout_width="20dp"
                android:layout_height="25dp"
                android:layout_marginBottom="18dp"
                android:layout_marginEnd="19dp"
                android:layout_marginRight="19dp"
                android:background="@drawable/arrow"
                android:elevation="2dp" />
        </LinearLayout>

    </LinearLayout>
</layout>

и в вашем классе манифеста

<application
        ...
        >
        <activity android:name=".YourActivity"
            android:windowSoftInputMode="adjustResize"
           >
        </activity>
</application>

enter image description here

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...