2016-07-05 52 views
3

我想爲Android構建一個簡單的聊天應用程序(使用Native SDK),並且在爲UI構建一個漂亮的佈局方面遇到了一些麻煩,特別是對於EditText和TextView元素。我想爲Android創造這樣的WhatsApp的應用程序:如何創建一個像TextView和EditText的WhatsApp?

enter image description here

的目標是創建一個形狀與這兩個元素的這種尖尖的邊緣。我已經做了一些研究,發現我必須使用shape標籤構造資源文件,並將其添加到android:background屬性中。但我無法弄清楚我將如何在圖像中創建那些尖銳的邊緣。任何幫助表示讚賞!

+1

我認爲這將是非常複雜的(如果可能的話),這樣做的形狀。創建這個背景會更容易[9-patch PNG](https://developer.android.com/guide/topics/resources/drawable-resource.html#NinePatch)。 –

+1

你可以手動繪製這個圖片作爲一個自定義的Drawable,但是如果有人把它作爲背景圖像(在Photoshop或其他)中,你可以將它設置爲EditText的背景,這可能會容易得多。 – NoChinDeluxe

+1

9-patch可以做到這一點,在ilustrator或其他圖像編輯器中創建具有邊框和右上角的圖像編輯器,並使用Android Studio創建9-patch – Adonys

回答

0
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

<ListView 
    android:background="#f1f1f1" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
</ListView> 

    <LinearLayout 
     android:padding="10dp" 
     android:gravity="center" 
     android:weightSum="1" 
     android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true"> 

     <EditText 
      android:paddingBottom="3dp" 
      android:layout_marginRight="10dp" 
      android:layout_weight=".70" 
      android:layout_width="match_parent" 
      android:layout_height="45dp" 
      android:background="@drawable/lgbg" 
      android:hint="Add item" /> 

     <ImageView 
      android:layout_gravity="center" 
      android:foregroundGravity="center" 
      android:padding="13dp" 
      android:background="@drawable/send" 
      android:layout_weight=".30" 
      android:layout_width="70dp" 
      android:layout_height="50dp" 
      android:src="@drawable/ic_send_white" /> 

    </LinearLayout> 

+0

雖然這可能會回答這個問題,但最好解釋答案的重要部分,以及OPs代碼可能存在的問題。 – pirho

相關問題