2017-01-13 8 views
0

layout_weightを使用して、EditTextフィールドのすぐ右側にボタンを表示しようとしています。LayoutWeightsが正しく要素をスケーリングしない

しかし、これは何が起こるかです:

enter image description here

は私のデザインビューに見えるようにコンパイルされたバージョンを取得する方法はありますか?ここで

は私のデザインビュー

enter image description here

そして、ここでは私のレイアウトコードです:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:layout_marginLeft="5dp" 
android:layout_marginRight="5dp" 
android:padding="10dp" 
android:scrollbars="none" 
tools:context="com.mycomapany.myapp.Views.MasterDetails.VehicleFragment"> 


<LinearLayout 
android:id="@+id/llMainView" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:orientation="vertical"> 


../// OTHER ELEMENTS 

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

<android.support.design.widget.TextInputLayout 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:layout_weight="2" 
    android:hint="VIN"> 

    <android.support.design.widget.TextInputEditText 
     android:id="@+id/editVIN" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_marginEnd="5dp" 
     android:background="@color/COLOR_TXI_GREY" 
     android:imeOptions="actionDone" 
     android:inputType="text" 
     android:maxLength="17" 
     android:maxLines="1"/> 
</android.support.design.widget.TextInputLayout> 

<ProgressBar 
    android:id="@+id/pbCheckVIN" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center" 
    android:visibility="gone"/> 

<Button 
    android:id="@+id/btnScanVIN" 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:layout_weight="1" 
    android:background="@color/COLOR_TXI_BLUE" 
    android:text="SCAN" 
    android:textColor="@color/COLOR_TXI_WHITE" 
    android:textStyle="bold"/> 
</LinearLayout> 


../// OTHER ELEMENTS 

</LinearLayout> 

答えて

-1

は、これを試してみてくださいより多くのリニアレイアウトを配置し、その後ワンドどのようなサイズ重量属性を与えますそのテキストとボタンを作成するこのような線形レイアウトは、ButtonとTextViewの表示の詳細のみを示しています。

<LinearLayout 
 
android:layout_width="match_parent" 
 
android:layout_height="match_parent" 
 
android:orientation="vertical">//main Linear Layout 
 
    <LinearLayout 
 
android:laout_weight="1"; 
 
android:layout_width="match_parent" 
 
android:layout_height="0dp" 
 
android:orientation="vertical">//another Linear Layout 
 
    //write code u want 
 
    </LinearLayout> 
 

 
<LinearLayout 
 
android:laout_weight="1"; 
 
android:layout_width="match_parent" 
 
android:layout_height="0dp" 
 
android:orientation="horizontal">//you wanted LinearLayout 
 

 
<android.support.design.widget.TextInputLayout 
 
    android:layout_width="0dp" 
 
    android:layout_height="match_parent" 
 
    android:layout_weight="2" 
 
    android:hint="VIN"> 
 

 
    <android.support.design.widget.TextInputEditText 
 
     android:id="@+id/editVIN" 
 
     android:layout_width="0dp" 
 
     android:layout_height="match_parent" 
 
     android:layout_marginEnd="5dp" 
 
     android:background="@color/COLOR_TXI_GREY" 
 
     android:imeOptions="actionDone" 
 
     android:inputType="text" 
 
     android:maxLength="17" 
 
     android:maxLines="1"/> 
 
</android.support.design.widget.TextInputLayout> 
 
</LinearLayout> 
 
</LinearLayout>
この

0

は、あなたの答えにコンテキストを提供してみてくださいTextInputEditText

+0

からandroid:layout_marginEnd="5dp"属性を削除してみてください。答えは問題を解決するかもしれないが、説明は多くの将来の問題を解決するかもしれない。問題を引き起こしていると思われるものと、その答えが解決する理由を含めるようにしてください。 – Newd

+0

@Newd android:layout_marginEndは、ビューの境界の外側にあるビューの最後の余分なスペースを指定します。これは、私は、EditTextとButtonの間のスペースを引き起こしていると思います。 – sats

関連する問題