2016-03-25 33 views
0

我有一个Android应用程序,其中包含一个RelativeLayout,其中包含TableLayoutAndroid - Scale TableLayout至屏幕尺寸

TableLayout之内,有3个ImageView s用于每个3 TableLayout行。 (总共制作9个)

我遇到的问题是每行中最后的ImageView部分被切断。

这是我目前的XML代码:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center" 
    tools:context=".Main"> 
    <TableLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentRight="true" 
      android:shrinkColumns="true" 
      android:id="@+id/TableLayout"> 
      <TableRow 
       android:id="@+id/TableRow1" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content"> 
       <ImageView 
        android:id="@+id/s1" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:padding="5dp"/> 
       <ImageView 
        android:id="@+id/s2" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:padding="5dp"/> 
       <ImageView 
        android:id="@+id/s3" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:padding="5dp"/> 
      </TableRow> 
    </TableLayout> 
</RelativeLayout> 

(行的其余部分是相同的)

我试图玩弄像fill_parentwrap_content值,但我还没有任何成功了。

我想将TableLayout缩放到屏幕大小,以便它在所有设备上都看起来不错,没有任何图像被切断。

以下是截图: screenshot

提前感谢!

+0

它是在右边还是下边?你可以添加一个截图吗? – RobinF

+0

@RobinF正在剪切图像。我会尽力得到一个截图。 –

+0

@RobinF我添加了一个截图,希望它有帮助。 –

回答

0

您可能想要使用LinearLayout作为父级,并且TableLayout使用内部权重,这样您的行和列将通过均匀分配可用的总空间来均匀分配。

此外,如果您希望图像适合分配的空间使用match_parent高度和重量与android:scaleType="fitXY"ImageViewsTableLayout内。其他图像缩放算法也可用于获得最佳效果(以适应您的需求)尝试并稍微玩一下,看看最适合您的是什么。

+0

使用'LinearLayout'无法运气,并用'scaleType =“fitXY”'缩放图像。还有其他建议吗? –

+0

比将android:stretchColumns =“*”添加到tablelayout并尝试使用不同的缩放算法,这些算法被建议作为ImageView属性的自动完成:> android:scaleType来阅读更多关于它们的信息,您可以查看这里 - http://developer.android.com/reference/android/widget/ImageView.ScaleType.html – crazyPixel