2017-01-05 2 views
1

編集画面の左にあるラベル付きの入力フィールドのリストが必要です。下部には、一式のボタンが必要です。中央に配置する必要があります。 ラベルには言語によって異なる幅があるため、EditTextビューは残りのスペースにまたがる必要があります。私はグリッドレイアウトを使用しています。なぜなら、すべてのEditTextビューを左に縦線に合わせる必要があるからです。残りのスペースをアンドロイド・ビューにする方法

私はこれを解決するために半日を過ごしましたが、私は進歩しません。私は得ることができる最も近いがこれです:

<?xml version="1.0" encoding="utf-8"?> 
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"> 

    <TextView 
     android:layout_column="0" 
     android:layout_row="0" 
     android:text="Label 1234545" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/tvHeightLabel"/> 

    <EditText 
     android:layout_column="1" 
     android:layout_row="0" 
     android:text="Some text which is too long that it could fit in one single row" 
     android:layout_gravity="fill_horizontal" 
     android:inputType="numberDecimal" 
     android:ellipsize="end" 
     android:id="@+id/etHeight" 
     android:layout_width="259dp"/> 

    <TextView 
     android:layout_column="0" 
     android:layout_row="1" 
     android:text="Label 2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/tvHeightLabel2"/> 

    <EditText 
     android:layout_column="1" 
     android:layout_row="1" 
     android:text="Some text which is too long that it could fit in one single row" 
     android:layout_gravity="fill_horizontal" 
     android:inputType="numberDecimal" 
     android:ellipsize="end" 
     android:id="@+id/etHeight2" 
     android:layout_width="259dp"/> 

    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_horizontal" 
     android:layout_row="3" 
     android:layout_column="0" 
     android:layout_columnSpan="2"> 

     <Button 
      style="?android:attr/buttonBarButtonStyle" 
      android:text="Button 1" 
      android:layout_height="wrap_content" 
      android:id="@+id/btCancel" 
      android:layout_weight="1" 
      android:layout_width="wrap_content"/> 

     <Button 
      style="?android:attr/buttonBarButtonStyle" 
      android:text="Button 2" 
      android:layout_height="wrap_content" 
      android:id="@+id/btSave" 
      android:layout_weight="1" 
      android:layout_width="wrap_content"/> 

    </LinearLayout> 

</GridLayout> 

このレイアウトは、次のようになります。

Layout set automatically by Android Studio

最初に動作するようだが、ラベルは、特定のサイズ、のEditTextビュー要素を超えたとき右の画面の脱却:

EditText views grow out of the screen

上記溶液は、のために働く、なぜ私も得ることはありませんラベルはわずかに成長します。 EditText要素の幅はAndroid Studioによって自動的に設定された259dpに設定されています。 (私はEditTextビューをデザイン画面上のプレビュー上にマウスでサイズ調整して配置しようとしましたが、上記のように特定のポイントで自動的に配置されました)

ビューを食べさせるには、そのコンテンツとは独立したままにしておくこと。テキストはスクロールできる、私はそれで大丈夫だ。私はレイアウトのコンセプトを全く理解していないような気がします。

答えて

0

パディングを使用してテキストの流れを制限します。

+0

パディングを使用する場所はどこですか? EditTextビューにパディングを追加すると、ビューのエッジとテキストの内容の間にスペースができるだけであることを理解しています。すべての利用可能なスペースを水平に見せるという私の問題を解決するにはどうすればいいですか? – Carsten

+0

あなたはあなたのグリッドビューの列の幅を修正し、いくつかのプロパティを追加する必要があると思います:android:layout_column = "0" android:layout_row = "0" android:layout_gravity = "fill" android:layout_columnWeight = "1" android:layout_rowWeight = "1" – bluedroid

関連する問題