2016-08-01 4 views
1

私はRelativeLayoutと、スペースを節約するために、数字が空であれば "隠す"(View.GONE)ことができる6つの要素を持っています。値が空になると、番号とその番号の「タイトル」が隠されます。あなたはこの画像で見ることができるように、すべての要素は、画面上でミックス: imageRelativeLayoutとView.GONEの問題

をこれがコードです:

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/largeImageView" 
    android:id="@+id/containerLayout" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true"> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textAppearance="?android:attr/textAppearanceMedium" 
     android:text="@string/phone" 
     android:id="@+id/phoneTitleTextView" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:layout_marginTop="20dp" /> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     android:text="Text" 
     android:id="@+id/homePhoneTextView" 
     android:layout_below="@+id/phoneTitleTextView" 
     android:layout_alignParentLeft="true" /> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     android:text="@string/home" 
     android:id="@+id/homeTitleTextView" 
     android:layout_below="@+id/phoneTitleTextView" 
     android:layout_alignLeft="@+id/workTitleTextView" 
     android:layout_alignStart="@+id/workTitleTextView" /> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     android:text="Text" 
     android:id="@+id/workPhoneTextView" 
     android:layout_below="@+id/homePhoneTextView" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" /> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     android:text="@string/work" 
     android:id="@+id/workTitleTextView" 
     android:layout_below="@+id/homeTitleTextView" 
     android:layout_alignLeft="@+id/mobileTitleTextView" 
     android:layout_alignStart="@+id/mobileTitleTextView" /> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     android:text="Text" 
     android:id="@+id/mobilePhoneTextView" 
     android:layout_below="@+id/workPhoneTextView" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" /> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     android:text="@string/mobile" 
     android:id="@+id/mobileTitleTextView" 
     android:layout_alignTop="@+id/mobilePhoneTextView" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentEnd="true" /> 
</RelativeLayout> 

私はのLinearLayoutで行くべきだと思いますが、私はそれをしようとすると、それは最悪の取得します。 ありがとうございます!

答えて

0

問題は、右の列の各エントリは、左の配置を決定するためにその下のエントリに依存するということです。一番下の行、または中央の行をGONEに設定した場合、突然エントリーはその下のビューを見つけることができず、デフォルトで左に揃えられます。

「モバイル」が最も長い文字列であり、「モバイル」の開始位置に揃えたいと思っていますが、これは堅牢なアプローチではありません。たとえば、ローカリゼーションは「モバイル」を最短の文字列にすることができなくなり、ロジックを破ります。

私はこれに似たレイアウトを作ると、通常は右の列にある要素を持つことになります。layout_alignParentLeft="true"それから大きな左余白を入れます。しかし、それはあなたが探している "右列の最大要素の幅に基づいて左揃え"の動作を達成することはできません。私は、T.MがTableLayoutと正しい軌道に乗っていると思っています。

0

ビューがGONEの場合は、ロードされておらず、layoutBelowの属性を使用しているためです。

あなたの質問に対しては正確な回答ではないかもしれませんが、それを達成する別の方法はuse TableLayout、次にremove the TableRow at runtimeです。

0

GONEの代わりにview.setVisibility(View.INVISIBLE)を使用

関連する問題