android - 如何在 EditText 中嵌入 View (带有按钮等)?

标签 android android-widget

我正在尝试弄清楚如何在 EditText 小部件中嵌入除 Drawable 之外的东西。具体来说,我想到的示例来自 Google Buzz 小部件:

screenshot (没有内联图片,抱歉,我是新手)

在不经意的观察者看来,有一个完整的布局对象固定在 EditText 的底部,其中包含一个 ImageView、一个 TextView 和一个 Button。

有人知道如何解决这个问题吗?或者我们认为这是 EditText 的自定义子类?

最佳答案

EditText + Button + ... 这是一个 FrameLayout,EditText 带有 fill_parent,Buttons 带有 layout_gravitiy:"bottom"。像这样:

<?xml version="1.0" encoding="utf-8"?> <!-- Main Layout (may be relative or whatever --> <RelativeLayout    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <!-- Layout for edittext and button -->
    <FrameLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">

        <EditText
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:lines="5"/>

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|right"
            android:layout_margin="5dip"
            android:text="Overflow"/>

    </FrameLayout>

    <!-- More layouts ..... -->   </RelativeLayout>

关于android - 如何在 EditText 中嵌入 View (带有按钮等)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3018050/

相关文章:

android - resultCode == RESULT_OK 在 redmi note3 中不起作用

java - 导入联系人仅导入联系人列表中的第一个联系人号码

android - 如何停止在图库小部件中滚动?

java - 适用于 Android 应用的 Linkedin Api 查询

android - 编辑文本焦点不起作用 android

java - 如何按一定百分比增加触摸面积?

java - Android studio ListView 不显示

android - 如何在服务中获取我的应用程序的 widgetID 和 ComponentName

android - 关于 Android "Attribute elevation is only used in API level 21 and higher"的说明

java - 将 XML 数据(文件)绑定(bind)到 android 中的 GridView ?