[英]Android Layout - How to create a dynamic tablelayout based on screen size?
[英]Android - Scale TableLayout to Screen Size
我有一个Android应用程序,其中包含一个带有TableLayout
的RelativeLayout
。
在TableLayout
中,对于3个TableLayout
行中的每行都有3个ImageView
。 (共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_parent
和wrap_content
类的值,但是还没有成功。
我想将TableLayout
缩放到屏幕的大小,以便在所有设备上看起来都不错,而不会截断任何图像。
提前致谢!
您可能希望使用LinearLayout
作为父级,并让TableLayout
在内部使用权重,这样,您的行和列将通过平均分配可用空间来平均分配。
同样,如果您希望图像适合分配的空间,请在高度和重量上都使用match_parent
,对于android:scaleType="fitXY"
在TableLayout
使用ImageViews
。 其他图像缩放算法也可用,因此为了获得最佳结果(以适应您的需求),请尝试一点,然后看看最适合您的算法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.