我以为我已经了解了Android的XML布局,但似乎我没有。 我想在一个屏幕上有四个 ImageView,同时查看四个图像。
它应该看起来像这样,其中 A 到 D 代表 ImageView :
DDDAAA
DDDAAA
BBBCCC
BBBCCC
我该怎么做?我以这种方式尝试过,但它不起作用。 Eclipse Editor 似乎也不太适合这个。是否有更好的布局来创建这些布局?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TableRow>
<ImageView android:id="@+id/ImageView01" android:layout_height="wrap_content" android:layout_width="wrap_content" ></ImageView>
<ImageView android:id="@+id/ImageView02" android:layout_height="wrap_content" android:layout_width="wrap_content"></ImageView>
</TableRow>
<TableRow>
<ImageView android:id="@+id/ImageView03" android:layout_height="wrap_content" android:layout_width="wrap_content"></ImageView>
<ImageView android:id="@+id/ImageView04" android:layout_height="wrap_content" android:layout_width="wrap_content"></ImageView>
</TableRow>
</RelativeLayout>
最佳答案
关于:
LinearLayout
,垂直
方向,包含所有内容- 然后是第一个
LinearLayout
,水平
方向- 将包含 D 和 A,
- 和相同类型的
LinearLayout
horizontal
方向,第二次,用于 B 和 C
并使用
android:layout_weight
- 和
android:gravity="center"
所以每个布局都占据足够的位置并且居中?
有点像这样,我会说:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:layout_weight="1"
>
<LinearLayout
android:id="@+id/DashboardNewPost"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_weight="1"
android:gravity="center"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/new_post"
/>
</LinearLayout>
<LinearLayout
android:id="@+id/DashboardPostsList"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_weight="1"
android:gravity="center"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/posts_list"
/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:layout_weight="1"
>
<LinearLayout
android:id="@+id/DashboardCommentsList"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_weight="1"
android:gravity="center"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/comments_list"
/>
</LinearLayout>
<LinearLayout
android:id="@+id/DashboardBlogParameters"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_weight="1"
android:gravity="center"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/blog_params"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
我想(未尝试)您甚至可以删除每个 ImageView
周围的 LinearLayout
,将它具有的属性添加到 ImageView
而不是...
(在我从中提取的应用程序中,我不得不添加那些 LinearLayout
,因为不仅仅是那些图像)
关于xml - Android XML 布局 - 一个屏幕上有 4 个 ImageView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3087693/