2010-06-09 55 views
2

我有一个视图,其中包含几个textViews一个ImageView和一个按钮。因为在小屏幕设备上(或在大屏幕上的横屏模式下)并不是全部都可见,所以我使用Scroll作为整个层级的父级,以允许用户查看所有信息。事情很糟糕,按钮必须位于视图的底部。然而,在大屏幕设备上,在按钮上留有足够的空间时,该按钮将立即放置在最后一个文本视图的下方,并且似乎占据了所有剩余空间(导致视图不协调)。尝试使用android:allignParentButtom =“true”,不仅仅是它没有效果,而是将按钮置于屏幕顶部。有没有人有任何想法我怎么能够完成我所描述的?ScrollView在android

这里的XML

<?xml version="1.0" encoding="utf-8"?> 
    <ScrollView 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/scroll_view" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerHorizontal="true"> 


    <RelativeLayout 
     android:id="@+id/gps_info_page1" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_centerHorizontal="true"> 

     <TextView 
      android:id="@+id/itsDateTimeValue" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentTop="true" 
      android:layout_centerHorizontal="true" 
      android:text="@string/eStrUnknown"> 
     </TextView> 

    <RelativeLayout 
      android:id="@+id/directions" 
      android:layout_centerHorizontal="true" 
      android:layout_below="@+id/itsDateTimeValue" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content"> 

     <TextView 
       android:id="@+id/itsDirectionValue" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="0" 
       android:layout_marginRight="2dip" 
       android:textSize="20sp"> 
     </TextView> 
     <TextView 
       android:id="@+id/itsOrientation" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:textSize="20sp" 
       android:layout_marginLeft="2dip" 
       android:text="@string/eStrUnknown" 
       android:layout_toRightOf="@+id/itsDirectionValue"> 
     </TextView> 
    </RelativeLayout> 



    <ImageView 
     android:id="@+id/itsImage" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/compass" 
     android:layout_below="@+id/directions" 
     android:layout_centerHorizontal="true"> 
    </ImageView> 

    <RelativeLayout> 
     ..."TextViews below the above image" 
    </RelativeLayout> 

    <RelativeLayout> 
     ..."TextViews below the above"   
    </RelativeLayout> 

    <RelativeLayout> 
    ..."TextViews below the above" 
    </RelativeLayout> 

    <RelativeLayout> 
    ..."TextViews below the above"    
    </RelativeLayout> 

    <RelativeLayout 
    ..."TextViews below the above" 
    </RelativeLayout> 


    <LinearLayout 
     android:id="@+id/div" 
     android:layout_width="fill_parent" 
     android:layout_height="1dip" 
     android:layout_below="@+id/sunset_layout" 
     android:background="#F333"> 
    </LinearLayout> 

    <Button //adding here android:alignParentBottom="true" has described above behavior 
    android:layout_marginBottom="3dip" 
    android:layout_marginTop="20dip" 
    android:id="@+id/done_button" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/eStrDone" 
    android:textSize="18sp" 
    android:layout_below="@+id/div" 
    android:layout_centerHorizontal="true"> 
    </Button> 


    </RelativeLayout> 

</ScrollView> 
+0

只是要清楚,你想这样的事情?:http://tinyurl.com/3azuawt – 2010-06-09 19:41:35

回答

1

你可以做的是根据屏幕上的编程改变大小。

这一行你在屏幕的密度:

scale = getResources().getDisplayMetrics().density;

,和本你的尺寸:

windowManager = getWindowManager(); display = windowManager.getDefaultDisplay(); screenWidth = display.getWidth(); screenHeight = display.getHeight();

,并用这个你可以得到的是其对portarit或landscape:

Configuration conf = context.getResources().getConfiguration();

有了这些信息,您可以随意修改屏幕。

有时是necesary做一些计算,因为不仅密度不同,但大小是不同的(像歌Nexus One和Droid)

希望这有助于。

丹尼尔

+0

你是什么意思“你可以随意修改屏幕”? – 2010-06-09 19:03:39

+0

我的意思是您可以根据屏幕大小,屏幕分辨率和位置为视图设置“固定”尺寸。因此,对于您的情况,您可以在最后一个按钮之前放置透明图像,并根据情况更改透明图像的大小。让我知道你是否需要更多信息。 – 2010-06-09 19:27:54

+0

那么,它可能会工作,但这是我宁愿避免的修复。 – 2010-06-09 19:33:26

0

你可以把你的滚动型的LinearLayout内,并设置重量滚动型为1