简体   繁体   English

Android布局中的隐藏空间

[英]Hidden space in layout in android

I have created a layout as shown in image below: 我创建了一个布局,如下图所示:

在此处输入图片说明

Now the problem its having so space between the image and the like/heart layout which i have highlighted in red line. 现在的问题是我在红线中突出显示的图像和喜欢/心形布局之间有这么大的空间。 I have tried a lot to remove it but the thing is it does not show the space in the graphical layout. 我已经尝试了很多删除它,但事实是它没有在图形布局中显示空间。 But whenever i try to run the application the space always shown. 但是,每当我尝试运行该应用程序时,总是显示该空间。

I don't understand where exactly this space is coming from. 我不知道这个空间到底来自哪里。 I have tried all the possible things. 我已经尝试了所有可能的方法。

Please help me out to remove the space. 请帮助我删除空间。

Here is the layout code: 这是布局代码:

<?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" 
    android:background="@drawable/bg_selector">

    <LinearLayout
        android:id="@+id/sp_color"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight=".9"
        android:orientation="vertical"
        android:padding="10dp" >

        <ImageView
            android:id="@+id/sp_image"
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_margin="5dp"
            android:layout_weight=".8"
            android:background="@drawable/baby1"
            android:scaleType="fitXY" />

        <TextView
            android:id="@+id/sp_profile"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="15dp"
            android:gravity="center"
            android:text="Hello World" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/sp_linh"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_marginLeft="15dp"
        android:layout_weight=".10"
        >

        <LinearLayout
            android:id="@+id/ll_clk_hrts"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:padding="5dp" >

            <ImageView
                android:id="@+id/sp_imageHeart"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:paddingRight="5dp"
                android:src="@drawable/heart" />

            <TextView
                android:id="@+id/sp_hearts"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="12"
                android:textSize="15sp" />
        </LinearLayout>

        <LinearLayout
            android:id="@+id/sp_ll_like_layout"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:padding="5dp" >

            <ImageView
                android:id="@+id/sp_imageLike"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:paddingLeft="5dp"
                android:src="@drawable/ic_like" />

            <TextView
                android:id="@+id/sp_likes"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:paddingLeft="5dp"
                android:text="4"
                android:textSize="15sp" />
        </LinearLayout>
    </LinearLayout>

</LinearLayout>

bg_selector code: bg_selector代码:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
      android:shape="rectangle" >

    <solid android:color="#EBEBEB" />

    <corners
        android:bottomLeftRadius="5dp"
        android:bottomRightRadius="5dp"
        android:topLeftRadius="5dp"
        android:topRightRadius="5dp" />
    <stroke android:width="1dp" 
        android:color="@android:color/black" 
       />

</shape>

Thanks. 谢谢。

Two ideas: 两个想法:

  • For the outer (first) LinearLayout , set android:layout_height="wrap_content" 对于外部(第一个) LinearLayout ,设置android:layout_height="wrap_content"
  • Or add to that outer layout an empty element (like Space ) as the last one, after the like bar, @+id/sp_linh , and give it enough weight to push up that bar. 或在该外部布局中添加一个空元素(例如Space )作为最后一个元素,位于类似栏@+id/sp_linh ,并赋予其足够的权重以向上推动该栏。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM