как установить ширину редактируемого текста в соответствии с шириной устройства - PullRequest
0 голосов
/ 28 сентября 2019

Я пытаюсь настроить текст редактирования, установив его размер в соответствии с размером устройства - 200 пикселей (для двух кнопок)

пробовал:

Display display = getWindowManager().getDefaultDisplay();
        Point size = new Point();
        display.getSize(size);
        int width = size.x - 200;

        LinearLayout.LayoutParams lparams = new LinearLayout.LayoutParams(width, LinearLayout.LayoutParams.MATCH_PARENT);

        editTextmessage = findViewById(R.id.input_chat_message);

        editTextmessage.setLayoutParams(lparams);

        editTextmessage.getLayoutParams().width = width;

и: editTextmessage.setWidth(size.x - 200); какое-либо решение для этого?PS: я гуглил и даже искал stackoverflow до того, как задал этот вопрос. edit: activity_chat.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".ChatActivity">

    <include
        android:id="@+id/chat_toolbar"
        layout="@layout/app_bar_layout"

        />

    <androidx.recyclerview.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/chat_toolbar"
        android:id="@+id/chat_list"
        android:layout_above="@id/private_chat_linear_layout"/>

    <LinearLayout
        android:id="@+id/private_chat_linear_layout"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:orientation="horizontal"
        android:layout_alignParentBottom="true"
        android:layout_alignParentStart="true">

        <EditText
            android:id="@+id/input_chat_message"
            android:layout_width="1dp"
            android:layout_height="match_parent"
            android:hint="@string/write_your_message_here"
            android:padding="0dp"
            android:background="@drawable/inputs"/>

        <ImageButton
            android:id="@+id/send_message_button_chat"
            android:layout_width="50dp"
            android:layout_height="wrap_content"
            app:srcCompat="@drawable/send_message" />
        <ImageButton
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:id="@+id/send_file_button_chat"
            app:srcCompat="@drawable/share_file"
            android:background="#D6D7D7"
            />

    </LinearLayout>




</RelativeLayout>

запросить дополнительный код, если требуется

1 Ответ

0 голосов
/ 29 сентября 2019

Я не уверен, что это то, что вы ищете, но я попробовал это так.

    EditText editText = findViewById(R.id.input_chat_message);

    DisplayMetrics displayMetrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
   // int height = displayMetrics.heightPixels;
    int width = displayMetrics.widthPixels;

   int editTextWidth = width - 200;
   editText.setLayoutParams(new LinearLayout.LayoutParams(editTextWidth,LinearLayout.LayoutParams.WRAP_CONTENT));

Надеюсь, это поможет.

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