如何使 IME 中的视图浮动在其他视图之上?
我正在尝试使 ListView 在我的 IME 中“浮动”在屏幕中间,就像 Swype 键盘一样:
我已经阅读了如何使用 FrameLayout 在 Activity 中执行此操作,但它在我的 IME 中不起作用,IME 是服务而不是 Activity。我的输入视图由作为根视图的 FrameLayout、包含多个控件的子relativelayout 以及也是 FrameLayout 的子视图的 ListView 组成。这是我的布局代码:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:gravity="center_horizontal" >
<!-- Most of the controls are children of this RelativeLayout -->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center" >
<Button android:id="@+id/btnOption1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="@+id/imgArrow"
android:layout_marginTop="10dp"
android:textSize="18dp"
android:textColor="#ffffff"
android:background="@drawable/button"
android:padding="4dp"
android:text="Option 1" />
<ImageView android:id="@id/imgArrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_centerHorizontal="true"
android:layout_alignBottom="@id/btnOption1"
android:layout_marginTop="10dp"
android:padding="4dp"
android:src="@drawable/arrow_right" />
<Button android:id="@+id/btnOption2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_toRightOf="@id/imgArrow"
android:layout_marginTop="10dp"
android:textSize="18dp"
android:textColor="#ffffff"
android:background="@drawable/button"
android:padding="4dp"
android:text="Option 2" />
<!-- Translate button -->
<Button android:id="@+id/btnContinue"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="@id/imgArrow"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:textSize="22dp"
android:textColor="#ffffff"
android:background="@drawable/button"
android:text="Translate!" />
<!-- Keyboard button -->
<ImageButton android:id="@+id/btnKeyboard"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@id/btnContinue"
android:layout_marginRight="4dp"
android:textColor="#ffffff"
android:background="@drawable/button"
android:src="@drawable/sym_keyboard_kb" />
<!-- Undo button -->
<ImageButton android:id="@+id/btnUndo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@id/btnContinue"
android:textColor="#ffffff"
android:background="@drawable/button"
android:src="@drawable/sym_keyboard_undo" />
</RelativeLayout>
<ListView android:id="@+id/menuOptions"
style="@style/optionsMenu" />
</FrameLayout>
ListView 和 IME 看起来像这样(在 SMS 应用程序内):
但我希望它看起来像这样:
换句话说,我希望它出现在外部 IME 输入视图。如果 Swype 可以做到,我知道我可以(需要一点帮助)。有什么建议吗?
提前致谢! 巴里
I am trying to make a ListView in my IME "float" in the middle of the screen, just like the Swype keyboard:
I've read how to do it in an Activity by using a FrameLayout, but it isn't working in my IME, which is a Service not an Activity. My input view consists of a FrameLayout as the root view, a child RelativeLayout containing several controls, and the ListView which is also a child of the FrameLayout. Here is my layout code:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:gravity="center_horizontal" >
<!-- Most of the controls are children of this RelativeLayout -->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center" >
<Button android:id="@+id/btnOption1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="@+id/imgArrow"
android:layout_marginTop="10dp"
android:textSize="18dp"
android:textColor="#ffffff"
android:background="@drawable/button"
android:padding="4dp"
android:text="Option 1" />
<ImageView android:id="@id/imgArrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_centerHorizontal="true"
android:layout_alignBottom="@id/btnOption1"
android:layout_marginTop="10dp"
android:padding="4dp"
android:src="@drawable/arrow_right" />
<Button android:id="@+id/btnOption2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_toRightOf="@id/imgArrow"
android:layout_marginTop="10dp"
android:textSize="18dp"
android:textColor="#ffffff"
android:background="@drawable/button"
android:padding="4dp"
android:text="Option 2" />
<!-- Translate button -->
<Button android:id="@+id/btnContinue"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="@id/imgArrow"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:textSize="22dp"
android:textColor="#ffffff"
android:background="@drawable/button"
android:text="Translate!" />
<!-- Keyboard button -->
<ImageButton android:id="@+id/btnKeyboard"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@id/btnContinue"
android:layout_marginRight="4dp"
android:textColor="#ffffff"
android:background="@drawable/button"
android:src="@drawable/sym_keyboard_kb" />
<!-- Undo button -->
<ImageButton android:id="@+id/btnUndo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@id/btnContinue"
android:textColor="#ffffff"
android:background="@drawable/button"
android:src="@drawable/sym_keyboard_undo" />
</RelativeLayout>
<ListView android:id="@+id/menuOptions"
style="@style/optionsMenu" />
</FrameLayout>
The ListView and IME look like this (inside the SMS app):
But I want it to look like this:
In other words I want it to appear outside the IME input view. If Swype can do it, I know I can (with a little help). Any suggestions?
Thanks in advance!
Barry
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了问题的解决方案,并在另一个线程中发布了答案: Android IME:显示自定义弹出对话框(如 Swype 键盘),可以在 TextView 中输入文本
Barry
I found the solution to my problem, and posted the answer in another thread: Android IME: showing a custom pop-up dialog (like Swype keyboard) which can enter text into the TextView
Barry