中间有 4 个 imageViews,如 2 行 * 2 行,适用于所有设备
4 imageViews in the center like 2 lines * 2 rows for all devices
我正在尝试将 4 个 imageView 放在 2 行 * 2 行中:
我这样做了:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/accueil">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/font"
android:src="@drawable/fond_menu"
android:scaleType="centerCrop"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="20dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/topLogo"
android:layout_marginTop="5dp"
android:src="@drawable/logo_bleu_petit"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/topText"
android:lineSpacingMultiplier="1.3"
android:textSize="16sp"
android:layout_below="@+id/topLogo"
android:layout_centerHorizontal="true"
android:width="260dp"
android:layout_marginTop="15dp"
android:gravity="center"
android:textIsSelectable="false"
android:layout_marginBottom="10dp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/firstBlock"
android:src="@drawable/encart_offres"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/topText"
android:layout_alignParentRight="true"
android:layout_marginRight="150dp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/secondBlock"
android:src="@drawable/encart_contact"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_below="@+id/topText"
android:layout_alignParentBottom="false"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="false"
android:layout_marginLeft="150dp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/thirdBlock"
android:src="@drawable/encart_actualites"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/firstBlock"
android:layout_marginTop="40dp"
android:layout_marginLeft="150dp"
android:layout_alignParentRight="true" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/fourthBlock"
android:src="@drawable/encart_mentions"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_below="@+id/secondBlock"
android:layout_marginTop="40dp"
android:layout_marginRight="150dp"
android:layout_alignParentLeft="true" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="80dp"
android:id="@+id/formulaire"
android:layout_marginTop="15dp"
android:layout_below="@+id/fourthBlock"
android:background="@drawable/bouton_formulaire"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/bottomText"
android:lineSpacingMultiplier="1.2"
android:gravity="center"
android:textColor="#626262"
android:textSize="14sp"
android:layout_centerHorizontal="true"
android:layout_marginTop="15dp"
android:width="270dp"
android:layout_below="@+id/formulaire" />
</RelativeLayout>
</ScrollView>
</RelativeLayout>
但是对于不同的设备,imageViews 粘在它们之间或重叠。我想我必须使用行和行,但我不知道如何使用它。
试试这个
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:id="@+id/font"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:scaleType="centerCrop"
android:src="@drawable/ic_launcher" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:scaleType="centerCrop"
android:src="@drawable/ic_launcher" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:scaleType="centerCrop"
android:src="@drawable/ic_launcher" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:scaleType="centerCrop"
android:src="@drawable/ic_launcher" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:scaleType="centerCrop"
android:src="@drawable/ic_launcher" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
为什么不用这样的 TableLayout?
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/scroll">
<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TableRow>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/topLogo1"
android:layout_marginTop="5dp"
android:src="@drawable/logo_bleu_petit"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/topLogo2"
android:layout_marginTop="5dp"
android:src="@drawable/logo_bleu_petit"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
</TableRow>
<TableRow>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/topLogo3"
android:layout_marginTop="5dp"
android:src="@drawable/logo_bleu_petit"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/topLogo4"
android:layout_marginTop="5dp"
android:src="@drawable/logo_bleu_petit"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
</TableRow>
</TableLayout>
</ScrollView>
我希望这能解决你的问题。
我正在尝试将 4 个 imageView 放在 2 行 * 2 行中:
我这样做了:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/accueil">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/font"
android:src="@drawable/fond_menu"
android:scaleType="centerCrop"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="20dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/topLogo"
android:layout_marginTop="5dp"
android:src="@drawable/logo_bleu_petit"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/topText"
android:lineSpacingMultiplier="1.3"
android:textSize="16sp"
android:layout_below="@+id/topLogo"
android:layout_centerHorizontal="true"
android:width="260dp"
android:layout_marginTop="15dp"
android:gravity="center"
android:textIsSelectable="false"
android:layout_marginBottom="10dp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/firstBlock"
android:src="@drawable/encart_offres"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/topText"
android:layout_alignParentRight="true"
android:layout_marginRight="150dp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/secondBlock"
android:src="@drawable/encart_contact"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_below="@+id/topText"
android:layout_alignParentBottom="false"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="false"
android:layout_marginLeft="150dp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/thirdBlock"
android:src="@drawable/encart_actualites"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/firstBlock"
android:layout_marginTop="40dp"
android:layout_marginLeft="150dp"
android:layout_alignParentRight="true" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/fourthBlock"
android:src="@drawable/encart_mentions"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_below="@+id/secondBlock"
android:layout_marginTop="40dp"
android:layout_marginRight="150dp"
android:layout_alignParentLeft="true" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="80dp"
android:id="@+id/formulaire"
android:layout_marginTop="15dp"
android:layout_below="@+id/fourthBlock"
android:background="@drawable/bouton_formulaire"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/bottomText"
android:lineSpacingMultiplier="1.2"
android:gravity="center"
android:textColor="#626262"
android:textSize="14sp"
android:layout_centerHorizontal="true"
android:layout_marginTop="15dp"
android:width="270dp"
android:layout_below="@+id/formulaire" />
</RelativeLayout>
</ScrollView>
</RelativeLayout>
但是对于不同的设备,imageViews 粘在它们之间或重叠。我想我必须使用行和行,但我不知道如何使用它。
试试这个
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:id="@+id/font"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:scaleType="centerCrop"
android:src="@drawable/ic_launcher" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:scaleType="centerCrop"
android:src="@drawable/ic_launcher" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:scaleType="centerCrop"
android:src="@drawable/ic_launcher" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:scaleType="centerCrop"
android:src="@drawable/ic_launcher" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:scaleType="centerCrop"
android:src="@drawable/ic_launcher" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
为什么不用这样的 TableLayout?
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/scroll">
<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TableRow>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/topLogo1"
android:layout_marginTop="5dp"
android:src="@drawable/logo_bleu_petit"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/topLogo2"
android:layout_marginTop="5dp"
android:src="@drawable/logo_bleu_petit"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
</TableRow>
<TableRow>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/topLogo3"
android:layout_marginTop="5dp"
android:src="@drawable/logo_bleu_petit"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/topLogo4"
android:layout_marginTop="5dp"
android:src="@drawable/logo_bleu_petit"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
</TableRow>
</TableLayout>
</ScrollView>
我希望这能解决你的问题。