1
votes

I am trying to create a custom Android keyboard. I want to put a TextView right on top of KeyboardView.

Here's the XML. On this layout, the TextView displays on the very top of the screen. But I want to put it right on top of the keyboard, regardless the height of the keyboard. I tried playing around with layout_align*, but can't seem to do it.

<?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/input_view"
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <TextView
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:text="Hello World" />
    </LinearLayout>

    <android.inputmethodservice.KeyboardView
        android:id="@+id/keyboard"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:keyPreviewLayout ="@layout/keyboard_preview"
        />
</RelativeLayout>

Here's the screenshot.

enter image description here

1
Hi i am getting a crash when i try to inflate layout with extra elements can you share how you inflate this view inside your service class plsAndroid

1 Answers

0
votes

Add android:layout_above attribute inside LinearLayout as in

<?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/input_view"
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_above="keyboard"
        android:layout_height="wrap_content">
        <TextView
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:text="Hello World" />
    </LinearLayout>

    <android.inputmethodservice.KeyboardView
        android:id="@+id/keyboard"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:keyPreviewLayout ="@layout/keyboard_preview"
        />
</RelativeLayout>