[英]Android - Scale TableLayout to Screen Size
I have an Android app that contains a RelativeLayout
with a TableLayout
inside of it. 我有一个Android应用程序,其中包含一个带有TableLayout
的RelativeLayout
。
Within the TableLayout
there are 3 ImageView
s for each of the 3 TableLayout
rows. 在TableLayout
中,对于3个TableLayout
行中的每行都有3个ImageView
。 (Making 9 in total) (共9个)
The problem I'm having is that the last ImageView
in each row is partially cut off. 我遇到的问题是每行的最后一个ImageView
被部分切除。
This is my current xml code: 这是我当前的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>
(The rest of the rows are the same) (其余各行相同)
I have tried playing around with values like fill_parent
and wrap_content
but I haven't had any success yet. 我尝试过使用fill_parent
和wrap_content
类的值,但是还没有成功。
I would like to scale the TableLayout
to the size of the screen, so that it looks good on all devices, without any of the images getting cut off. 我想将TableLayout
缩放到屏幕的大小,以便在所有设备上看起来都不错,而不会截断任何图像。
Thanks in advance! 提前致谢!
You'd probably want to use a LinearLayout
as the parent and have the TableLayout
use weights inside, this way your rows and columns will spread evenly by dividing the total space available evenly. 您可能希望使用LinearLayout
作为父级,并让TableLayout
在内部使用权重,这样,您的行和列将通过平均分配可用空间来平均分配。
Also in case you want the images to fit the allocated space use match_parent
both for height and weight with android:scaleType="fitXY"
for the ImageViews
inside the TableLayout
. 同样,如果您希望图像适合分配的空间,请在高度和重量上都使用match_parent
,对于android:scaleType="fitXY"
在TableLayout
使用ImageViews
。 Other image scaling algorithms are also available so for the best results (to fit into your needs) try and play with it a little bit and see what fits you the most. 其他图像缩放算法也可用,因此为了获得最佳结果(以适应您的需求),请尝试一点,然后看看最适合您的算法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.