0

두 화면 사이에 편집 텍스트를 올바르게 배치하여 모든 화면 크기에서 전체 너비를 멋지게 배치 할 수있는 방법을 찾으려고합니다.안드로이드에서 편집 텍스트를 가로로 올바르게 배치하는 방법은 무엇입니까?

<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

너희들이 도와 수 있기를 바랍니다

여기 내 XML입니다! . 당신이 android:layout_weight="1"를 사용하는 대신에 당신이 맞게 EditText에 맞게하려는 경우 폭을 고정해야

답변

1

<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

아 많은 덕분에 동료를 도왔다. 그럼 "무게"란 무엇입니까? –

+0

기본적으로 Weight는 LinearLayouts와 함께 수평 또는 수직으로 만 작동합니다. Layout은 레이아웃의 높이 또는 너비를 기준으로 특정 무게로 가중치를 지정합니다. 예를 들어 세 가지 재료를 정렬하려면 동일한 크기로 고정해야합니다. linearLayout 아래의 모든 뷰는 동일한 크기를 갖습니다. – k0sh

+1

그래, 남자를 할 것입니다. explaination을 주셔서 감사합니다 –

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

봅니다 확인하기 위해 2 ImageView (또는 무언가)의 중간에 Edittextlayout_weight="1" :

<?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>