2011-12-02 61 views
1

它能夠將視圖放在左側,但在屏幕外?如何將視圖置於屏幕外?

我想顯示三個視圖(圖片),但只有在屏幕上的第二對接,是這樣的:

+---------------------+ 
    |  Screen  | 
+-------+ +-------+ +-------+ 
|  | |  | |  | 
| image | | image | | image | 
|  | |  | |  | 
+-------+ +-------+ +-------+ 
    |      | 
    +---------------------+ 

我想開始在這種形式可見。

回答

3

您可以使用幾種方法:

  • Gallery(http://developer.android.com/resources/tutorials/views/hello-gallery.html)
  • HorizontalScrollView(HTTP://開發商.android.com/reference/android/widget/Horizo​​ntalScrollView.html)
  • ViewPager(http://android-developers.blogspot.com/2011/08/horizo​​ntal-view-swiping-with-viewpager.html)

現在的選擇取決於您想要在您的應用中執行的操作。

希望這會有所幫助! 如果您需要更具體的東西,請拍攝!

+0

我寫裏面放視圖(RelativeLayout的)代碼,但在負荷顯示我從左邊第一個視圖,第二,第三。但我想正確顯示:1/2視圖,1視圖,1/2視圖 - 中心的第二個視圖,加載後立即: – Nips

+1

在這種情況下,我會拒絕ViewPager和Horizo​​ntalScrollView解決方案。可以使用Gallery和將當前項目設置爲第二個圖像由於圖像不是全屏,所以還會顯示其他兩個圖像 –

1

在XML中,嘗試使用:

android:paddingLeft 
+0

我從代碼中加載它... – Nips

+1

嘗試'setPadding()'then – Caner

1

你也可以RelativeLayout的做到這一點。我認爲它有點像HTML中的浮動div,非常有趣。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content"> 

<RelativeLayout android:id="@+id/left_body" 
    android:gravity="center" 
    android:layout_alignParentLeft="true" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 
    <ImageView android:background="@drawable/house" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"/> 
</RelativeLayout> 

<RelativeLayout android:id="@+id/right_body" 
    android:gravity="center" 
    android:layout_alignParentRight="true" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 
    <ImageView android:background="@drawable/house" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"/> 
</RelativeLayout> 

<RelativeLayout android:id="@+id/main_body" 
    android:layout_toRightOf="@id/left_body" 
    android:layout_toLeftOf="@id/right_body" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <ImageView android:background="@drawable/house" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"/> 
</RelativeLayout> 

相關問題