2017-03-26 7 views
1

첨부 된 이미지에서 나오는 Layout을 만들고 싶지만 움직이지 못하거나 겹치기 때문에 너비와 높이가 완벽하게 맞지 않습니다. 나는 수평으로 listview을 가지고 싶다. 나는 LinerLayout 내부에 빨간색과 4 개의 직사각형을 가진 오렌지색을 넣을 것이다. (어느 것을 시도했는지는 Relative이 될 것이고, 안에 넣을 버튼은 imagebutton이 될 것이다.이 XML을 달성하기 위해 상대와 선형을 결합하는 방법은 무엇입니까?

FrameLayout을 넣으려고했는데 Relative으로 조금 더 연주 할 수 있지만 항상 왼쪽 위 모서리에 배치하고 해당 위치로 옮길 방법이 없습니다. 오른쪽 또는 아래로 나는 유사하거나 비슷한 일을하고있다 평방. 누군가로 모든 하시겠습니까?

enter image description here

내 코드는 오렌지색과 빨간색 사각형으로 내 이미지를 얻을 수 없습니다.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:padding="16dp" 
android:stretchColumns="1"> 


<FrameLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="111dp" 
     android:orientation="horizontal"></LinearLayout> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="173dp"> 

    </RelativeLayout> 
</FrameLayout> 

+0

코드를 게시하십시오. – Rahul

+0

내 XML 코드는 불가능하기 때문에 내 코드는 쓸모가 없으므로''linearlayout''과''RelativeLaoyut''만으로''framelayout''을 넣을 수는 있지만 걱정하지 않아도됩니다. 이제는 업데이트합니다. 내 코드와 내 질문 ..... –

+0

@ 라시 내 코드를 업데이 트했습니다 제발, 내 질문에 도와주세요 –

답변

1

이 레이아웃보십시오 :/드로어 블/사진 border.xml 고해상도의

<?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="match_parent" 
    android:orientation="vertical" 
    android:padding="5dp" 
    android:weightSum="5"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:background="@drawable/border" 
     android:orientation="horizontal"> 

     <ListView 
      android:id="@+id/list_item" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"></ListView> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="4" 
     android:orientation="vertical"> 


     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_weight="2" 
      android:orientation="horizontal" 
      android:weightSum="2"> 


      <ImageButton 
       android:layout_width="0dp" 
       android:layout_height="match_parent" 
       android:layout_weight="1" 
       android:background="@drawable/border" 
       android:src="@mipmap/ic_launcher" /> 

      <ImageButton 
       android:layout_width="0dp" 
       android:layout_height="match_parent" 
       android:layout_weight="1" 
       android:background="@drawable/border" 
       android:src="@mipmap/ic_launcher" /> 
     </LinearLayout> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_weight="2" 
      android:orientation="horizontal" 
      android:weightSum="2"> 


      <ImageButton 
       android:layout_width="0dp" 
       android:layout_height="match_parent" 
       android:layout_weight="1" 
       android:background="@drawable/border" 
       android:src="@mipmap/ic_launcher" /> 

      <ImageButton 
       android:layout_width="0dp" 
       android:layout_height="match_parent" 
       android:layout_weight="1" 
       android:background="@drawable/border" 
       android:src="@mipmap/ic_launcher" /> 
     </LinearLayout> 
    </LinearLayout> 
</LinearLayout> 

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

    <stroke 
     android:width="3dp" 
     android:color="#000000" /> 

    <corners android:radius="0dp" /> 
</shape> 

출력

enter image description here

+0

놀라운, 감사합니다! +1 –

+0

당신은 환영합니다 ... 기꺼이 도와 드리겠습니다. – rafsanahmad007

+0

당신은''stroke''로 1 개의 배경을 넣었습니다. 그러나 4 개의 imagebutton 모두에 배경색이 1 가지라면,''borders.xml'을 넣을 수 있습니까? '배경색이 다른가? –

0

상대 레이아웃 부모합니다.

<RelativeLayout android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 

    <LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation=horizontal" 
    android:alignParentTop="" 
    android:id="llTopH".....> 
     <your code for top layout> 
    </LinearLayout> 


    <LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation=horizontal" 
    android:layout_below="llTopH" 
    android:weightSum = "2" 
    android:id="llTopH2".....> 

    <LineraLayout 
     android:layout_width="0dp" 
     android:weight = "1" 
    android:layout_height="wrap_content" 
     /> 

    <LineraLayout 
     android:layout_width="0dp" 
     android:weight = "1" 
    android:layout_height="wrap_content" 
     /> 

this will two layouts on 2nd line 

</LinearLayout> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation=horizontal" 
    android:layout_below="llTopH2" 
    android:weightSum = "2" 
    android:id="llTopH3".....> 

     <LineraLayout 
     android:layout_width="0dp" 
     android:weight = "1" 
    android:layout_height="wrap_content" 
     /> 

     <LineraLayout 
     android:layout_width="0dp" 
     android:weight = "1" 
    android:layout_height="wrap_content" 
     /> 

this will two layouts on 3rd line 

</LinearLayout> 

</RelativeLayout>  
0
<?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="match_parent" 
    android:orientation="vertical"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:orientation="horizontal"> 

    <ListView 
     android:id="@+id/listview" 
     android:rotation="-90" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

    </ListView> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="4" 
     android:orientation="vertical"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="2" 
     android:orientation="horizontal" 
     android:weightSum="2"> 


     <ImageButton 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:src="@mipmap/ic_launcher" /> 

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

      android:src="@mipmap/ic_launcher" /> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="2" 
     android:orientation="horizontal" 
     android:weightSum="2"> 


     <ImageButton 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:src="@mipmap/ic_launcher" /> 

     <ImageButton 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:src="@mipmap/ic_launcher" /> 
    </LinearLayout> 
    </LinearLayout> 
<