如何将视图置于屏幕外?

问题描述:

它能够将视图放在左侧,但在屏幕外?如何将视图置于屏幕外?

我想显示三个视图(图片),但只有在屏幕上的第二对接,是这样的:

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

我想开始在这种形式可见。

您可以使用几种方法:

  • 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和将当前项目设置为第二个图像由于图像不是全屏,所以还会显示其他两个图像 –

在XML中,尝试使用:

android:paddingLeft 
+0

我从代码中加载它... – Nips

+1

尝试'setPadding()'then – Caner

你也可以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>