Как встроить вид (с кнопками и т. Д.) В текстовый редактор - PullRequest
8 голосов
/ 11 июня 2010

Я пытаюсь понять, как встраивать вещи, другие , чем Drawables, в виджет EditText.Конкретно пример, о котором я думаю, взят из виджета Google Buzz:

снимок экрана (нет встроенного изображения, извините, я новичок)

случайный наблюдатель, что в нижней части EditText закреплен целый объект макета, содержащий ImageView, TextView и Button.

У кого-нибудь есть идеи, как это осуществить?Или мы думаем, что это пользовательский подкласс EditText?

Ответы [ 3 ]

15 голосов
/ 11 июня 2010

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>
1 голос
/ 23 ноября 2010

Вы можете использовать макет фрейма для встраивания Button в EditText, здесь я даю пример кода для встраивания TextView в EditText, просто измените TextView как Button

<FrameLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_x="40px"
        android:layout_y="35px"
        >        

    <EditText android:id="@+id/twt_post_content" android:layout_gravity="center_vertical"
        android:layout_width="320dp" android:layout_height="140dp"
        android:paddingTop="5dp" android:imeOptions="actionDone"
        android:gravity="left" android:focusableInTouchMode="true"
        android:maxLength="140" android:ellipsize="end" />
            <TextView
                android:text="123" 
                android:paddingLeft="270dp"      
                android:paddingTop="100dp"   
                android:layout_alignParentRight="true"
                android:id="@+id/twt_content_count"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"              
                android:textColor="@color/red"
                android:layout_gravity="center"              
                android:background="@color/transparent"/>    
                </FrameLayout>        
0 голосов
/ 11 июня 2010

Я думаю, что здесь они создали фон для своего макета, который выглядит как EditText. Затем они добавили EditText с выключенным фоном и пришли кнопки.

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