[英]Horizontal ScrollView above a Button from LinearLayout
我想要實現的是這樣的:
關鍵是:點擊底部布局上的圓圈按鈕后,將出現一個HorizontalScrollView,其中包含產品的可能顏色(我必須下載)。 我嘗試過這樣的事情:
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >
<LinearLayout
android:id="@+id/lay_productdetailed_bottombar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/transparent"
android:gravity="center_vertical"
android:orientation="horizontal" >
<Button
android:id="@+id/btn_productdetailed_fullscreen"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Full" />
<Button
android:id="@+id/btn_productdetailed_colors"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Colors" />
<Button
android:id="@+id/btn_productdetailed_sizes"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Sizes" />
<Button
android:id="@+id/btn_productdetailed_buy"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Buy" />
</LinearLayout>
<HorizontalScrollView
android:id="@+id/hscroll_productdetailed_colors"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/btn_productdetailed_colors" >
<LinearLayout
android:id="@+id/lay_productdetailed_colors"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="2dp" >
<ImageButton
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_gravity="center_vertical" />
<ImageButton
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_gravity="center_vertical" />
</LinearLayout>
</HorizontalScrollView>
</RelativeLayout>
那兩個ImageButtons僅用於測試,以觀察它們在屏幕上的位置(Eclipse)。
此代碼似乎根本沒有將按鈕上方的水平滾動視圖對齊。 關於如何實現這一目標的任何想法?
PS。 另一個問題是:是否可以像在圖片中那樣使這些按鈕變成圓形,而無需創建擴展Shape的類?
您不能添加規則來放置不是RelativeLayout
對於這些視圖的直接同級的視圖的RelativeLayout
子級。 這意味着您的HorizontalScrollView
不能相對於該Button
放置,因為Button
並未作為擁有HorizontalScrollView
的RelativeLayout
的直接子項放置。
充其量,您可以將HorizontalScrollView
放置在lay_productdetailed_bottombar LinearLayout
上方,但是,正如我所說,這不會給您相對於Button
定位控件。 另一種方法是保存HorizontalScrollView
的PopupWindow
。
從圖像判斷,您可能希望HorizontalScrollView
圍繞Button
的中心居中,而這在xml布局中是無法完成的,您只能通過手動計算尺寸來做到這一點。
是否可以像在圖片中那樣使這些按鈕變圓,而無需創建擴展Shape的類?
不,您需要自己創建它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.