试图在对话框上获取按钮以发表评论

时间:2019-02-04 09:14:43

标签: android android-layout

我要发送类似于Instagram评论部分的按钮。但是,当我运行该应用程序时,仅出现“文本字段”。

这是我的XML

Popup.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:background="@drawable/dialog_bg"
    android:padding="10px">
//Receive the comment from Api
    <android.support.v7.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/popup_rcv">
    </android.support.v7.widget.RecyclerView>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_gravity="bottom">
        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/new_comment_et"
            android:hint="Please enter Comment"/>
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/comment_btn"
            android:text="Submit"
            />
    </LinearLayout>
</LinearLayout>

预先感谢

1 个答案:

答案 0 :(得分:2)

  

我要发送类似于Instagram评论部分的按钮。但是,当我运行该应用程序时,仅出现“文本字段”。

由于您的EditText宽度为match_parent,因此只需在您的 EditText

只需在您的 android:layout_weight="1"

中添加 EditText

示例代码

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:background="@drawable/dialog_bg"
    android:padding="10px">
//Receive the comment from Api
    <android.support.v7.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/popup_rcv">
    </android.support.v7.widget.RecyclerView>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_gravity="bottom">
        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/new_comment_et"
            android:layout_weight="1"
            android:hint="Please enter Comment"/>
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/comment_btn"
            android:text="Submit"
            />
    </LinearLayout>
</LinearLayout>