2017-02-09 36 views
0

布局代码:如何获得android的这个特定的屏幕布局?

Layout Code

所以基本上我想要的高度,有一半为Android的屏幕和B是在上留下A.所以A的顶部上方就像一个背景图像和B例如,你可以说例如像一张脸一样的图片。我如何解决这个问题?

这是我迄今为止,但它似乎没有工作?也许我使用Relativelayout不正确?我需要像一个div这样的容器。我假设如果我把它包装在一个relativelayout或类似div的东西,它会解决,但它不会。

<LinearLayout 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="0.5"> 

    <ImageView 
     android:id="@+id/bground" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:scaleType="fitXY" 
     android:src= "@drawable/background" /> 

    <ImageView 
     android:id="@+id/profileimage" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:src= "@drawable/face" /> 

    </RelativeLayout> 
</LinearLayout> 

回答

2

试试这个:使用Framelayout为ImageView的

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:weightSum="2"> 

    <FrameLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1"> 

     <ImageView 
      android:id="@+id/bground" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:background="#ff574f" /> 

     <ImageView 
      android:id="@+id/profileimage" 
      android:layout_width="100dp" 
      android:layout_height="100dp" 
      android:layout_gravity="top|left" 
      android:background="#32cd32" /> 

    </FrameLayout> 

    <FrameLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1"> 

    </FrameLayout> 
</LinearLayout> 

使用android:src的图像

enter image description here

+0

非常感谢你,我正在寻找什么! – DiderDrogba344

0

您可以轻松地通过只使用RelativeLayout的实现它。

<RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="0.5"> 

    <ImageView 
     android:id="@+id/bground" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:scaleType="fitXY" 
     android:src= "@drawable/background" /> 

    <!-- You need to add the profile image view after the background view --> 
    <!-- so that it is placed above the background. --> 
    <!-- Lock the size for profile, don't fill the whole screen --> 
    <ImageView 
     android:id="@+id/profileimage" 
     android:layout_width="100dp" 
     android:layout_height="100dp" 
     android:src= "@drawable/face" /> 

</RelativeLayout> 

您还可以使用android:layout_alignParentTop="true"android:layout_alignParentLeft="true"profileimage视图,使其在RelativeLayout的左上方。