2016-05-12 3 views
0

私のスクリーンショットに見られるように、EditTextのようなビューはオーバーフローまたは消滅しています。そのため、複数行のEditTextの右側にスクロールバーが表示されません。Androidで再生回数がオーバーフローまたは消滅しました5

どうすれば修正できますか?私はmatch_parentとfill_parentを試しましたが、違いを見ることはできません。 'wrap_content'はフォームにとってはうまくありません。ここで

Screenshot Android Studio, EditText overflows

私のxmlです:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 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:orientation="vertical" 
    tools:context=".MyActivity"> 

    <GridLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:columnCount="2"> 

     <TextView android:text="Label for first EditText" /> 

     <EditText 
      android:id="@+id/et_id" 
      android:layout_width="match_parent" 
      android:lines="1" 
      android:maxLength="13" 
      android:maxLines="1" /> 

     <TextView android:text="Another Label for another ET" /> 

     <EditText 
      android:id="@+id/et_new_description" 
      android:layout_width="match_parent" 
      android:lines="3" 
      android:maxLines="10" 
      android:inputType="textMultiLine" 
      android:scrollbars="vertical" <!-- can't see this --> 
      android:scrollbarAlwaysDrawVerticalTrack="true"/> 

    </GridLayout> 

    <android.support.v7.widget.ButtonBarLayout 
     android:layout_width="match_parent" 
     android:layout_height="?attr/actionBarSize" 
     android:layout_alignParentBottom="true"> 

     <Button 
      android:id="@+id/button_cancel" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:drawableLeft="@drawable/filter" 
      android:text="cancel" /> 

     <Button 
      android:id="@+id/button_save" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:drawableLeft="@android:drawable/ic_menu_save" 
      android:text="save" /> 

    </android.support.v7.widget.ButtonBarLayout> 
</RelativeLayout> 
+0

あなたのビューは 'layout_width'と' layout_height'の両方を必要としていますか、それらを表示していないのでしょうか、スタイルや何かで扱っていますか? – zgc7009

+0

属性はこれ以上ありません。 – EV221

+0

@ EV221デバイス上で実行してみてください。レイアウトエディタでは、実際のデバイスに表示される方法とまったく同じように表示されないことがあります。 – Karakuri

答えて

0

私はこれを達成するための適切な方法は、android:layout_columnWeight属性であると思います。ここにサンプルがあります:

<GridLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:columnCount="2" 
    ... > 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_column="0" 
     android:text="Label" 
     ... /> 

    <EditText 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_column="1" 
     android:layout_columnWeight="1" 
     ... /> 

    <!-- Same pattern for other labels and text fields --> 

</GridLayout> 

ただし、この属性はAPI 21(Lollipop)からのみ使用できます。あなたは、あなたのbuild.gradleファイルにdependenciesブロックに

compile 'com.android.support:gridlayout-v7:23.3.0' 

を追加するために必要とする、代わりにGridLayoutのサポートバージョンを使用して、あなたのレイアウトファイルに

<android.support.v7.widget.GridLayout> 

を使用することができます。これは私があなたにお勧めするものです。


あなたはまた、グリッドレイアウトのサポートバージョンを使用せずにロリポップよりも古いバージョンをサポートしたい場合は、ここであなたが望む効果を達成する別の方法です:

<GridLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:columnCount="2" 
    ... > 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_column="0" 
     android:text="Label" 
     ... /> 

    <EditText 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_column="1" 
     android:layout_gravity="fill_horizontal" 
     ... /> 

    <!-- Same pattern for other labels and text fields --> 

</GridLayout> 

あなたはandroid:layout_width="wrap_content"の代わりを使用する必要がありますEditTextandroid:layout_width="0dp"、わかりません。

+0

ありがとうございます。古いバージョンの2番目のアドバイスは私を助けました。あなたの最初のアドバイスは私のためには機能しません。 – EV221

関連する問題