2016-09-28 66 views
0

我知道這不可能是最好的標題,所以如果您有更好的標題,請編輯。我將如何創建此佈局

好的,所以我有一個模擬了我想在android中創建的部分設計,我將在後面進行介紹。

我不是最好的自定義形狀的工作,所以我想我可能會沿着Images with clickable areas的路線。這意味着我只是導入圖像,並只監視用戶是否點擊屏幕的一部分。

什麼是最好的方法?

如果用XML創建它更好,你有一個很好的教程,你可以指向我。

感謝 enter image description here

+0

創建的RelativeLayout作爲主要佈局。接下來添加LinearLayout(垂直),其中將包含兩個水平佈局。並添加Imageview(設置爲alignCenterinparent =圓圈類型之前關閉相對 –

+0

聽起來像一個很好的方法,我會給它之前。 – SammyG

回答

3

這可能有助於

<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:id="@+id/activity_main" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:paddingBottom="16dp" 
android:paddingLeft="16dp" 
android:paddingRight="16dp" 
android:paddingTop="16dp"> 

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

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

     <Button 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:text="Button 1"/> 

     <Button 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:text="Button 2"/> 


    </LinearLayout> 


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

     <Button 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:text="Button 3"/> 

     <Button 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:text="Button 4"/> 

    </LinearLayout> 

</LinearLayout> 

<Button 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_centerInParent="true" 
    android:background="@drawable/circle"/></RelativeLayout> 

請繪製文件夾這個文件命名爲圓形按鈕背景圈子

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

<size android:width="200dp" android:height="200dp" /> 
<solid android:color="@android:color/holo_red_light" /></shape> 

看起來像這樣

Your Layout

+0

看起來不錯,謝謝。由於某些原因,圓形不是在設計器中呈現,但我將不得不找出最新的錯誤(我有形狀名爲圈)但這是偉大的感謝,我將這標記爲答案:)(現在已經呈現....新的Android工作室是一個小馬車) – SammyG

+0

你有問題圈?只需在res中創建drawable文件夾並在裏面保留一個xml文件以獲得圓形背景,比如說說circle.xml並將其保存在其中。代碼:<?xml version =「1.0」encoding =「utf-8」?> Abhishek

+0

將此文件作爲背景添加到中心按鈕佈局文件 – Abhishek

0

下面是一個全面的測試佈局

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 

    <Button 
     android:id="@+id/btn_1" 
     android:layout_width="100dp" 
     android:layout_height="wrap_content" 
     android:text="Button one"/> 

    <Button 
     android:id="@+id/btn_2" 
     android:layout_width="100dp" 
     android:layout_height="wrap_content" 
     android:layout_toRightOf="@id/btn_1" 
     android:text="Button two"/> 

    <Button 
     android:id="@+id/btn_3" 
     android:layout_width="100dp" 
     android:layout_height="wrap_content" 
     android:text="Button three" 
     android:layout_below="@id/btn_1"/> 

    <Button 
     android:id="@+id/btn_4" 
     android:layout_width="100dp" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/btn_2" 
     android:layout_toRightOf="@id/btn_3" 
     android:text="Button four"/> 

    <ImageView 
     android:id="@+id/logo" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true" 
     android:translationZ="10dp" 
     android:src="@drawable/ti_logo"/> 

</RelativeLayout> 
0

@ SammyG您可以在此佈局按照您的要求修改..

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:id="@+id/activity_main" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
tools:context="com.example.android.stackoverflow_test.MainActivity"> 

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

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

     <TextView 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:background="@android:color/holo_green_dark" 
      android:padding="20dp" /> 

     <TextView 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:background="@android:color/black" 
      android:padding="20dp" /> 
    </LinearLayout> 

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

     <TextView 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:background="@android:color/holo_red_dark" 
      android:padding="20dp" /> 

     <TextView 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:background="@android:color/holo_blue_bright" 
      android:padding="20dp" /> 
    </LinearLayout> 
</LinearLayout> 

<ImageView 
    android:layout_width="150dp" 
    android:layout_height="150dp" 
    android:layout_centerInParent="true" 
    android:background="@mipmap/ic_launcher" /></RelativeLayout>