give equal space between ImageViews

故事扮演 提交于 2019-12-25 01:23:54

问题


i am trying to add some social images in my app about me screen but i am facing a problem of giving equal spaces between imageviews.

my images looks like this:

but i want to make them look like this:

my code:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/RelativeLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/about_screen" >

    <LinearLayout
        android:id="@+id/llSocialMediaContainer"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:orientation="horizontal"
        android:paddingBottom="@dimen/bottum_padding" >

        <!-- Facebook -->

        <ImageView
            android:layout_width="@dimen/social"
            android:layout_height="@dimen/social"
            android:src="@drawable/facebook" />

        <!-- Twitter -->

        <ImageView
            android:layout_width="@dimen/social"
            android:layout_height="@dimen/social"
            android:src="@drawable/twitter" />

        <!-- Google+ -->

        <ImageView
            android:layout_width="@dimen/social"
            android:layout_height="@dimen/social"
            android:src="@drawable/google" />

        <!-- Linkedin -->

        <ImageView
            android:layout_width="@dimen/social"
            android:layout_height="@dimen/social"
            android:src="@drawable/linkedin" />

        <!-- Blog -->

        <ImageView
            android:layout_width="@dimen/social"
            android:layout_height="@dimen/social"
            android:src="@drawable/blog" />

        <!-- Youtube -->

        <ImageView
            android:layout_width="@dimen/social"
            android:layout_height="@dimen/social"
            android:src="@drawable/youtube" />

        <!-- Email -->

        <ImageView
            android:layout_width="@dimen/social"
            android:layout_height="@dimen/social"
            android:src="@drawable/mail" />
    </LinearLayout>

</RelativeLayout>

回答1:


There you go, modify the code accordingly, learn about android:layout_weight it is usefull in such situations:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <ImageView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:src="@drawable/ic_launcher" />

    <ImageView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:src="@drawable/ic_launcher" />

    <ImageView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:src="@drawable/ic_launcher" />

    <ImageView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:src="@drawable/ic_launcher" />

    <ImageView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:src="@drawable/ic_launcher" />

</LinearLayout>



回答2:


set layout_margin property of imageview to give space between thos image view.




回答3:


Use <Space/> element in your Linearlayout between the imageviews to add equal space. You can assign the width using the weight property of LinearLayouts to get equally spaced icons in all different form factors.

Example:

<LinearLayout
        android:id="@+id/llSocialMediaContainer"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:orientation="horizontal"
        android:paddingBottom="@dimen/bottum_padding" >

        <!-- Facebook -->

        <ImageView
            android:layout_width="@dimen/social"
            android:layout_height="@dimen/social"
            android:src="@drawable/facebook" />

        <Space
            android:layout_width="15dp"
            android:layout_height="match_parent"/>
        <!-- Twitter -->

        <ImageView
            android:layout_width="@dimen/social"
            android:layout_height="@dimen/social"
            android:src="@drawable/twitter" />

</LinearLayout>



回答4:


Try

    <ImageView
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="@dimen/social"
        android:src="@drawable/facebook" />

For each of the ImageViews. This should give them equal width of the total linearlayout width. I'm not sure if this will stretch your images or not, if it does you might need to set the scale type.



来源:https://stackoverflow.com/questions/27268144/give-equal-space-between-imageviews

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!