gpt4 book ai didi

java - 如何给 LinearLayout 充气(用于 android 键盘)?

转载 作者:行者123 更新时间:2023-11-29 09:50:20 27 4
gpt4 key购买 nike

我正在尝试创建一个 android 键盘,现在我希望它只是膨胀,即显示来自 main.xml 的线性布局

这是java文件

package keyboard.rob.com;

import ...

public class zyz extends InputMethodService
implements KeyboardView.OnKeyboardActionListener {

private KeyboardView mInputView;

@Override public void onCreate() {
super.onCreate();
}

@Override public View onCreateInputView() {
mInputView = (KeyboardView) getLayoutInflater().inflate(R.layout.main, null);
return mInputView;
}
}

主.xml

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android" android:layout_gravity="center" android:id="@+id/LL_whole" android:orientation="vertical" android:clickable="false">


<LinearLayout android:layout_width="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android" android:background="@layout/backrep" android:layout_gravity="center" android:id="@+id/LL_total" android:orientation="vertical" android:layout_height="wrap_content">
<LinearLayout android:layout_height="wrap_content" android:layout_width="match_parent" android:background="@drawable/spell_frame" android:layout_marginBottom="10px" android:layout_marginTop="5px" android:layout_gravity="center" android:id="@+id/LL_spell" android:paddingLeft="10px">
</LinearLayout>


<LinearLayout android:layout_height="wrap_content" android:orientation="horizontal" android:layout_gravity="center" android:layout_width="wrap_content" android:id="@+id/LLrow1">

</LinearLayout>
<LinearLayout android:layout_height="wrap_content" android:layout_gravity="center" android:orientation="horizontal" android:layout_width="wrap_content" android:id="@+id/LLrow2"></LinearLayout>
<LinearLayout android:layout_height="wrap_content" android:layout_gravity="center" android:orientation="horizontal" android:layout_width="wrap_content" android:id="@+id/LLrow3"></LinearLayout>
<LinearLayout android:layout_height="wrap_content" android:layout_gravity="center" android:orientation="horizontal" android:layout_width="wrap_content" android:id="@+id/LLrow4">
</LinearLayout>

</LinearLayout>


</LinearLayout>

及其崩溃的错误:

08-29 20:21:28.128: ERROR/AndroidRuntime(10227): java.lang.ClassCastException: android.widget.LinearLayout

有什么想法吗?谢谢!

最佳答案

试试下面的代码..

package keyboard.rob.com;

import ...

public class TotalKeyboard extends InputMethodService
implements KeyboardView.OnKeyboardActionListener {

private LinearLayout mInputView;

@Override public void onCreate() {
super.onCreate();
}

@Override public View onCreateInputView() {
mInputView = (LinearLayout) getLayoutInflater().inflate(R.layout.main, null);
return mInputView;
}
}

关于java - 如何给 LinearLayout 充气(用于 android 键盘)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7242749/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com