2014-05-11 37 views
0

enter image description here左對齊的垂直觀點邊緣的RelativeLayout

我怎樣才能讓500 (TextView)比賽的上面checkbox左邊緣?

我使用RelativeLayout

<ImageView 
    android:id="@+id/group_indicator" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:src="@drawable/expander_open_holo_dark" /> 

<TextView 
    android:id="@+id/lblListHeader" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:paddingLeft="?android:attr/expandableListPreferredItemPaddingLeft" 
    android:textSize="17sp" /> 

<CheckBox 
    android:id="@+id/GroupCheckBox" 
    android:layout_width="wrap_content" 
    android:layout_height="fill_parent" 
    android:layout_alignParentRight="true" 
    android:focusable="false" 
    android:paddingRight="10dp" 
    android:scaleX="2" 
    android:scaleY="2" /> 

<SeekBar 
    android:id="@+id/GroupSeekbar" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignLeft="@id/lblListHeader" 
    android:layout_alignParentLeft="true" 
    android:layout_toLeftOf="@+id/GroupSeekCount" 
    android:layout_below="@id/lblListHeader" 
    android:focusable="false" 
    android:max="1000" 
    android:paddingBottom="0dp" 
    android:paddingLeft="?android:attr/expandableListPreferredItemPaddingLeft" 
    android:paddingTop="20dp" > 
</SeekBar> 

<TextView 
    android:id="@+id/GroupSeekCount" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentRight="true" 
    android:paddingRight="10dp" 
    android:paddingTop="20dp" 
    android:text="500" 
    android:layout_below="@id/GroupCheckBox" 

    /> 

回答

1
// try this way,hope this will help you... 

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:padding="5dp"> 

    <ImageView 
     android:id="@+id/group_indicator" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:layout_alignParentLeft="true" 
     android:src="@drawable/expander_open_holo_dark" /> 

    <CheckBox 
     android:id="@+id/GroupCheckBox" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:focusable="false" 
     android:layout_alignParentTop="true" 
     android:layout_alignParentRight="true" 
     android:scaleX="2" 
     android:scaleY="2" /> 

    <TextView 
     android:id="@+id/lblListHeader" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:paddingLeft="?android:attr/expandableListPreferredItemPaddingLeft" 
     android:layout_alignParentTop="true" 
     android:layout_toRightOf="@id/group_indicator" 
     android:layout_toLeftOf="@id/GroupCheckBox" 
     android:textSize="17sp" /> 

    <SeekBar 
     android:id="@+id/GroupSeekbar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:focusable="false" 
     android:max="1000" 
     android:paddingBottom="0dp" 
     android:layout_below="@id/lblListHeader" 
     android:layout_toLeftOf="@id/GroupCheckBox" 
     android:layout_alignBaseline="@id/lblListHeader" 
     android:paddingLeft="?android:attr/expandableListPreferredItemPaddingLeft" 
     android:paddingTop="20dp" /> 

    <TextView 
     android:id="@+id/GroupSeekCount" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:layout_below="@id/GroupCheckBox" 
     android:layout_toRightOf="@id/GroupSeekbar" 
     android:paddingTop="10dp" 
     android:text="500"/> 

</RelativeLayout> 
+0

謝謝。雖然這與Evan的建議相同。我正在尋找只使用RelativeLayout –

+0

現在我編輯了我的回答,我已經使用RelativeLayout完成了你的需求,所以請看看這個。 –

+0

This works great ..你能告訴我我失蹤的關鍵部分嗎?似乎有很多佈局的變化。 –

1

我會去這麼多的不同。

嘗試將擴展器和列表標題分組爲水平線性佈局,然後將複選框和500文本分組爲垂直線性佈局。最後,這兩個線性佈局應該嵌套在水平線性佈局中。

+0

我能做到這一點,但我想保持它在單一的ViewGroup由於性能原因 –

+0

好吧,那麼請嘗試使該複選框和500的文本固定寬度,器的paddingRight屆時將關閉匹配的寬度,他們應該排隊罰款。 –

+0

有沒有辦法,我可以使500 textview的寬度等於複選框而不對其進行硬編碼。我擔心硬編碼它不會在不同的顯示器上正確縮放它 –

1

首先定義CheckBox,然後纔是TextView。
然後設置的TextView的layout_width到match_parent(因此,它需要的剩餘空間)

此外,ImageView的可以成爲TextView的(複合繪製)的一部分,以減少控制數:
這樣做:在TextView的定義,設置這些屬性:

android:drawableLeft="@drawable/expander_open_holo_dark" 
android:drawablePadding="8dp" 

然後,你可以修改代碼組指標:

Drawable drw = getContext().getResources().getDrawable(R.drawable.expander_open_holo_dark); 
lblListHeader.setCompoundDrawablesWithIntrinsicBounds(drw, null, null, null); 

更妙的是(總注意優化設計的目的),您可以使用CheckedTextView控件,以便在單個控件中顯示圖像,文本和複選標記(因爲它擴展了TextView,它可以保存複合可繪製以及TextView一樣)。

當然,您可以將刻度標記向右移動。

+0

500 TextView是最後定義的。 500在下一行,如果我將它設置爲500,它會走到最左邊。 –

+0

所以!它是「GroupSeekCount」 - 嗯,我沒有正確理解這個問題。所以,非常簡單,將它(可選)對齊父級的底部和CheckBox左邊。完成。 –