0

Я пытаюсь понять, как правильно смоделировать текст редактирования между двумя видами, чтобы он занимал всю ширину во всех размерах экрана.Как правильно размещать текст редактирования по горизонтали в android?

Вот мой XML:

<LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:orientation="horizontal" 
       android:layout_marginTop="10dp"> 
       <ImageView 
        android:layout_width="50dp" 
        android:layout_height="50dp" 
        android:layout_marginLeft="5dp" 
        android:src="@drawable/country_india"/> 
       <EditText 
        android:layout_width="250dp" 
        android:layout_height="wrap_content" 
        android:hint="Leave a comment" 
        android:layout_gravity="bottom"/> 
       <ImageButton 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:src="@drawable/icon_pencil_2_small" 
        android:background="@color/white" 
        android:layout_gravity="bottom" 
        android:layout_marginBottom="5dp"/> 
      </LinearLayout> 

Вот как это выглядит: enter image description here

Надеется, что вы, ребята, можете помочь! .

ответ

1

вы должны использовать android:layout_weight="1" вместо фиксации ширины, если вы хотите, чтобы соответствовать EditText, чтобы поместиться в

<LinearLayout 
    android:layout_height="wrap_content" 
    android:layout_marginTop="10dp" 
    android:layout_width="match_parent" 
    android:orientation="horizontal"> 

    <ImageView 
     android:layout_height="50dp" 
     android:layout_marginLeft="5dp" 
     android:layout_width="50dp" 
     android:src="@drawable/country_india"/> 

    <EditText 
     android:hint="Leave a comment" 
     android:layout_gravity="bottom" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:layout_width="0dp"/> 

    <ImageButton 
     android:background="@color/white" 
     android:layout_gravity="bottom" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="5dp" 
     android:layout_width="wrap_content" 
     android:src="@drawable/icon_pencil_2_small"/> 
</LinearLayout> 
+0

Ah, который помог родственную спасибо много. Итак, что такое «вес»? –

+0

В основном вес работает только с LinearLayouts, горизонтальным или вертикальным, он сообщает макету, чтобы вес или основание высоты или ширины основывался на ориентации макета на конкретный вес, например, чтобы выровнять три элемента, при этом их размер должен быть таким же, как и вы должны использовать на каждом взгляде на вес 1. так что все виды под линейкойLayout будут иметь одинаковый размер – k0sh

+1

да будет делать человек. Спасибо за объяснение –

3

Попробуйте это: -

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="10dp" 
    android:orientation="horizontal"> 

    <ImageView 
     android:src="@drawable/country_india" 
     android:layout_width="50dp" 
     android:layout_height="50dp" 
     android:layout_marginLeft="5dp" 
     android:contentDescription="@string/app_name" /> 

    <EditText 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom" 
     android:layout_weight="1" 
     android:hint="Leave a comment" /> 

    <ImageButton 
     android:src="@drawable/icon_pencil_2_small" 
     android:background="@color/white" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom" 
     android:layout_marginBottom="5dp" 
     android:contentDescription="@string/app_name" /> 
</LinearLayout> 
+1

не пишите только «code», добавьте описание в ответ. – Ironman

2

Добавить андроида: layout_weight = "1" to editText

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="10dp" 
    android:orientation="horizontal"> 

    <ImageView 
     android:src="@drawable/country_india" 
     android:layout_width="50dp" 
     android:layout_height="50dp" 
     android:layout_marginLeft="5dp" 
     android:contentDescription="@string/app_name" /> 

    <EditText 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom" 
     android:layout_weight="1" 
     android:hint="Leave a comment" /> 

    <ImageButton 
     android:src="@drawable/icon_pencil_2_small" 
     android:background="@color/white" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom" 
     android:layout_marginBottom="5dp" 
     android:contentDescription="@string/app_name" /> 
</LinearLayout> 
3

Используйте этот код

<LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal" 
      > 
      <ImageView 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       /> 
      <EditText 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:hint="Leave a comment" 
       android:layout_weight="3" 
       /> 
      <ImageButton 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
      /> 
     </LinearLayout> 
+2

не пишите только «code», добавьте описание в ответ. – Ironman

0

Я бы сделал это таким образом, если бы был вами. Залейте вес, и вы хорошо пойдете.

<LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal" 
      android:layout_marginTop="10dp" 
      android:weightSum="1.5"> 
      <ImageView 
       android:layout_width="0dp" 
       android:layout_height="50dp" 
       android:layout_marginLeft="5dp" 
       android:src="@drawable/country_india" 
       android:layout_weight="0.25"/> 
      <EditText 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:hint="Leave a comment" 
       android:layout_gravity="bottom" 
       android:layout_weight="1"/> 
      <ImageButton 
       android:layout_width="0dp" 
       android:layout_height="50dp" 
       android:src="@drawable/icon_pencil_2_small" 
       android:background="@color/white" 
       android:layout_gravity="bottom" 
       android:layout_marginBottom="5dp" 
       android:layout_weight="0.25"/> 
     </LinearLayout> 
0

Попробуйте сделать свой Edittextlayout_weight="1" в середине 2 ImageView (или что-то):

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:layout_width="match_parent" 
       android:layout_height="72dp" 
       android:orientation="horizontal"> 

    <ImageView 
     android:id="@+id/address_item_image_view" 
     android:layout_width="24dp" 
     android:layout_height="24dp" 
     android:layout_gravity="center" 
     android:layout_margin="5dp" 
     android:src="@drawable/com_facebook_tooltip_black_background"/> 

    <EditText 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom" 
     android:hint="This is an edit text" 
     android:layout_weight="1"/> 

    <ImageView 
     android:id="@+id/address_item_arrow_image_view" 
     android:layout_width="18dp" 
     android:layout_height="18dp" 
     android:layout_gravity="center" 
     android:layout_marginEnd="5dp" 
     android:layout_marginRight="5dp" 
     android:src="@drawable/messenger_bubble_large_blue"/> 

</LinearLayout> 

 Смежные вопросы

  • Нет связанных вопросов^_^