1

私はEditTextのビューを均等にしようとしています。 しかし、私は彼らが正しく整列するように見えることができない、と私はEditTextのサイズを増やすことはできません。最初はRelativeLayoutで試してみましたが、物事を正確に位置づけることができましたが、サイズはまだありませんでした。私は水平に切り替えるとlayout_weightEditTextの両方のフィールドを自動的に調整することができましたが、そうではないようです。提案はありますか? このカスタムビューは、画面に表示するときに、垂直のLinearLayoutに追加されます。TextViewとEditTextを水平のLinearLayoutに正しく配置するにはどうすればよいですか?

マイレイアウトファイル:

<?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="wrap_content" 
    android:padding="1dp" 
    android:weightSum="1" 
    android:orientation="horizontal"> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="0.6" 
     android:gravity="center_vertical" 
     android:textColor="@color/ws_blue" 
     android:background="#00ffff" 
     android:textAppearance="?android:attr/textAppearanceMedium" 
     android:text="Settings Item: " 
     android:id="@+id/itemLabel" /> 

    <EditText 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="0.4" 
     android:textColor="@color/ws_blue" 
     android:textColorHint="@color/ws_hint" 
     android:background="#ffff00" 
     android:id="@+id/et_item_value" /> 

</LinearLayout> 

のAndroidメーカープレビュー:私の携帯電話から

Android Studio Preview

実際のスクリーンショット:

Phone Screenshot

+0

は、幅のTextViewする0dpとのEditTextを設定し、マージンは、私は右のAndroidのプレビューで見えることEr.Arjunsaini @ 'TableLayout' –

+0

@SathishKumarJのおかげでEDITTEXTも残さ私のデバイス上で上記のスクリーンショットと同じように見えます。 –

+0

をチェックしてくださいよ、 –

答えて

4

enter image description hereを使用して、よりcolumnsCountとスパンを設定することができ、あなたのコードは次のとおりです。コードの下 を使用すると、表示したレイアウトファイルと同じですスクリーンショット。

<TableLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="8dp"> 
    <TableRow> 
     <TextView 
      android:layout_weight="1" 
      android:gravity="center" 
      android:text="Device ID:" 
      android:textColor="@android:color/holo_green_dark" 
      android:textStyle="bold" /> 
     <TextView 
      android:layout_weight="1" 
      android:text="00:00:00:00:00:00" 
      android:textColor="@android:color/holo_green_dark" 
      android:textStyle="bold" /> 
    </TableRow> 
    <TableRow android:layout_marginTop="8dp"> 
     <TextView 
      android:layout_weight="1" 
      android:text="Wifi Presets:" 
      android:textColor="@android:color/holo_blue_dark" 
      android:textSize="18sp" 
      android:textStyle="bold" /> 
     <Spinner 
      android:layout_marginRight="20dp" 
      android:layout_weight="1" 
      android:textColor="@android:color/holo_green_dark" 
      android:textStyle="bold" /> 
    </TableRow> 
    <TableRow android:layout_marginTop="8dp"> 
     <TextView 
      android:layout_weight="1" 
      android:background="@android:color/holo_blue_bright" 
      android:text="SSID:" 
      android:textColor="@android:color/holo_blue_dark" 
      android:textSize="18sp" 
      android:textStyle="bold" /> 
     <EditText 
      android:layout_marginLeft="16dp" 
      android:layout_weight="1" 
      android:background="#FFFF00" 
      android:hint="SSID" 
      android:textColor="@android:color/holo_blue_dark" 
      android:textColorHint="@android:color/darker_gray" 
      android:textSize="18sp" 
      android:textStyle="bold" /> 
    </TableRow> 
    <TableRow android:layout_marginTop="8dp"> 
     <TextView 
      android:layout_weight="1" 
      android:background="@android:color/holo_blue_bright" 
      android:text="Password:" 
      android:textColor="@android:color/holo_blue_dark" 
      android:textSize="18sp" 
      android:textStyle="bold" /> 
     <EditText 
      android:layout_marginLeft="16dp" 
      android:layout_weight="1" 
      android:background="#FFFF00" 
      android:hint="Password" 
      android:inputType="textPassword" 
      android:textColor="@android:color/holo_blue_dark" 
      android:textColorHint="@android:color/darker_gray" 
      android:textSize="18sp" 
      android:textStyle="bold" /> 
    </TableRow> 
    <TableRow android:layout_marginTop="8dp"> 
     <TextView 
      android:layout_weight="1" 
      android:text="Security Type:" 
      android:textColor="@android:color/holo_blue_dark" 
      android:textSize="18sp" 
      android:textStyle="bold" /> 

     <Spinner 
      android:layout_marginRight="20dp" 
      android:layout_weight="1" 
      android:textColor="@android:color/holo_green_dark" 
      android:textStyle="bold" /> 
    </TableRow> 
</TableLayout> 
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="wrap_content" 
    android:orientation="horizontal" 
    android:padding="1dp" 
    android:weightSum="1"> 

    <TextView 
     android:id="@+id/itemLabel" 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="0.6" 
     android:background="#00ffff" 
     android:layout_margin="20dp" 
     android:padding="10dp" 
     android:gravity="center_vertical" 
     android:text="Settings Item: " 
     android:textAppearance="?android:attr/textAppearanceMedium" 
     android:textColor="@android:color/holo_blue_dark"/> 

    <EditText 
     android:id="@+id/et_item_value" 
     android:layout_margin="20dp" 
     android:layout_width="0dp" 
     android:padding="10dp" 
     android:layout_height="match_parent" 
     android:layout_weight="0.4" 
     android:background="#ffff00" 
     android:textColor="@android:color/holo_blue_dark" 
     android:textColorHint="@android:color/darker_gray"/> 

</LinearLayout> 
1

私はGridLayoutで作業することをお勧めします。あなたは

<GridLayout 
.... 
android:columnCount="2"> 

を使用することができますし、より大きなのEditTextが必要な場合は、こちら

<EditText 
..... 
android:layout_columnSpan="2"/> 
0

推奨回答に加えて、パーセントサポートライブラリを使用できます。 Googleが作成したこのライブラリでは、RelativeLayoutFrameLayoutを作成できます。幅、高さ、および余白のパーセンテージを定義するという利点があります。あなたは、次のようにそれを使用することができ、この依存関係を追加した後

compile 'com.android.support:percent:23.3.0' // note that the version number 
              // might change due to updates 

:ちょうどあなたのGradleアプリファイルに次の行を追加し、それを使用するには、これは単なるサンプルであることを

<android.support.percent.PercentRelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <TextView 
     android:id="@+id/itemLabel" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:alignParentLeft="true" 
     android:background="#00ffff" 
     android:layout_marginLeftPercent="10%" 
     android:gravity="center_vertical" 
     android:text="Settings Item: " 
     android:textAppearance="?android:attr/textAppearanceMedium" 
     android:textColor="@android:color/holo_blue_dark"/> 

    <EditText 
     android:id="@+id/et_item_value" 
     app:layout_marginRightPercent="10%" 
     android:alignParentRight="true" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_widthPercent="40%" 
     android:background="#ffff00" 
     android:textColor="@android:color/holo_blue_dark" 
     android:textColorHint="@android:color/darker_gray"/> 

</android.support.percent.PercentRelativeLayout> 

注意をし、あなたがパーセントサポートライブラリの詳細については、ニーズに応じて

それを修正することができ、このlink

希望THIに従ってください。 sが役立ちます:)あなたは体重をかけるとき

関連する問題