2017-02-09 80 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的左上方。