将图像视图以线性布局对齐到屏幕顶部

时间:2016-08-23 08:30:33

标签: android android-linearlayout

我正在尝试在android studio中的线性布局顶部对齐图像image with space at top of picture。我在图片上看到了一个空格。我想摆脱那个空间。尝试了一些没有成功的事情!任何人都有一个线索如何做到这一点???感谢

<?xml version="1.0" encoding="utf-8"?>
<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"
tools:context="com.bourgeois.michel.relativesinglescreenapp.MainActivity">

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/topLinear"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

      <ImageView
        android:id="@+id/toppicture"
        android:layout_width="match_parent"
        android:layout_height="300dp"
        android:src="@drawable/danielarias" />

    <TextView
        android:id="@+id/phone"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingBottom="10dp"
        android:textColor="#ff6600"
        android:textStyle="bold"
        android:paddingLeft="10dp"
        android:text="Phone"/>


    <TextView
        android:id="@+id/number"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingLeft="10dp"
        android:textColor="#000"
        android:textStyle="normal"
        android:text="424-278-8938"/>


    <View
        android:id="@+id/line"
        android:layout_width="fill_parent"
        android:layout_height="2dp"
        android:layout_marginTop="2dp"
        android:layout_marginBottom="10dp"
        android:background="#ff6600"/>
     </LinearLayout>

     <LinearLayout mlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">



    <TextView
        android:id="@+id/address"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/text"
        android:paddingBottom="20dp"
        android:paddingLeft="10dp"
        android:textColor="#000"
        android:textStyle="bold"
        android:text="Address: 5867 W 3rd St, Los Angeles, CA 90036"

        />

    <TextView
        android:id="@+id/text"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/button"
        android:fontFamily="sans-serif-condensed"
        android:paddingBottom="1dp"
        android:textAlignment="center"
        android:textColor="#000"
        android:textSize="16sp"
        android:text="Learn How To Dance Milonguero Tango Style!"/>

    <TextView
        android:id="@+id/thursday"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fontFamily="sans-serif-condensed"
        android:paddingBottom="5dp"
        android:textAlignment="center"
        android:textColor="#000"
        android:textSize="16sp"
        android:text="Every Thursday Night"/>
    <TextView
        android:id="@+id/hour"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fontFamily="sans-serif-condensed"
        android:paddingBottom="5dp"
        android:textAlignment="center"
        android:textColor="#000"
        android:textSize="16sp"
        android:text=" 8:30pm to 9:30pm"/>

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:layout_marginBottom="15dp"
        android:text="Join Us" />

3 个答案:

答案 0 :(得分:1)

问题可能与您的图像来源宽度和高度有关。你的xml中没有marginTop。尝试将android:scaleType="fitXY"添加到ImageView

答案 1 :(得分:1)

使用ImageView,如:

<ImageView
    android:layout_width="match_parent"
    android:layout_height="300dp"  
    android:scaleType="fitXY"/>  

答案 2 :(得分:0)

尝试添加

android:adjustViewBounds="true"

ImageView个参数中,添加scaleType="fitXY"会拉伸图像以避免它。

相关问题