2013-08-30 1 views
0

Я пытаюсь сделать макет, как описано ниже. Я не понимаю, как точно реализовать макет. enter image description hereПодстановка макета Android

В макете и вышеупомянутом шестиугольнике есть текст, который мне нужно динамически изменять из кода.

Я попытался подобным образом упомянутый here

Но шестиугольник еще отсечение. Я использую следующий код.

<RelativeLayout 
     android:id="@+id/Llfirstamount" 
     android:layout_width="100dp" 
     android:layout_height="wrap_content" 
     android:background="@color/layoutcolor1" 
     android:clickable="true" 
     android:clipChildren="false" > 

     <TextView 
      android:id="@+id/my_first_text" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:android:layout_alignParentBottom="true" 
      android:android:layout_alignParentLeft="true" 
      android:padding="15dp" 
      android:text="Amount" 
      android:textColor="@android:color/white" /> 

     <TextView 
      android:id="@+id/my_second_text" 
      android:layout_width="25dp" 
      android:layout_height="25dp" 
      android:layout_alignParentRight="true" 
      android:layout_alignParentTop="true" 
      android:layout_marginTop="-20dp" 
      android:background="@drawable/hexagon" 
      android:clipToPadding="false" 
      android:contentDescription="@string/contentdesc_peso_logo" 
      android:gravity="center" 
      android:text="x5" /> 
    </RelativeLayout> 

Я не знаю, это единственный путь, или правильный путь или есть гораздо лучший способ реализации this.I'm очень смущен. Пожалуйста, помогите !!! спасибо ..

EDIT:

Ok спасибо за ваши ответы, используя два вида текста с пользовательским фоном хорошей и чистая идея. Теперь я использую отредактированный код, но шестиугольник перегружен, как показано ниже .. enter image description here

я упускаю что-то я также добавил

android:clipToPadding="false" 

и

android:clipChildren="false" 

в моем коде.

ответ

3

Это будет делать это ..

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    tools:context=".MainActivity"> 

    <TextView 
     android:id="@+id/textView2" 
     android:layout_width="wrap_content" 
     android:layout_height="50dp" 
     android:background="#ccc" 
     android:gravity="center_vertical" 
     android:layout_centerInParent="true" 
     android:padding="5dp" 
     android:text="@string/hello_world" /> 

    <TextView 
     android:id="@+id/textView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_above="@+id/textView2" 
     android:layout_marginLeft="-25dp" 
     android:layout_marginBottom="-25dp" 
     android:layout_toRightOf="@+id/textView2" 
     android:background="@drawable/ic_launcher" /> 


</RelativeLayout> 

ВЫВОД: enter image description here

Good Luck :)

+0

Вы всегда можете сравнить ваш код с моим кодом;). Я использовал 'android: layout_centerInParent =" true "' для моего серого 'TextView' –

+1

Хммм .. но это не проблема, я думаю ... если вы поместите текстовые представления в другой относительный макет, то это не сработает ... И мне нужно иметь родительский элемент для двух текстовых просмотров .. потому что нужный макет на самом деле является кнопкой ... и у меня есть 6 похожих кнопок в моем родительском макете – Audi

0

Если вам нужно изменить текст из кода, вы, вероятно, не захотите использовать ImageView.

попробовать с двумя TextViews (зеленый и один гексагональную, который будет принимать изображение в качестве фона)

<RelativeLayout 
     android:id="@+id/Llfirstamount" 
     android:layout_width="wrap_content" 
     android:layout_marginTop="40dp" 
     android:layout_height="wrap_content" 
     android:background="@drawable/layout" 
     android:clickable="true" 
     android:clipChildren="false" 
     android:orientation="horizontal" > 
     <TextView android:id="@+id/my_first_text" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:android:layout_alignParentLeft="true" 
      android:android:layout_alignParentBottom="true" 
     > 
     </TextView> 
     <TextView android:id="@+id/my_second_text" 
      android:layout_width="25dp" 
      android:layout_height="25dp" 
      android:android:layout_alignParentTop="true" 
      android:android:layout_alignParentRight="true" 
      android:contentDescription="@string/contentdesc_peso_logo" 
      android:background="@drawable/hexagon" /> 
    </RelativeLayout> 

Затем вы можете использовать Activity.findViewById(), чтобы получить ссылки на ваши TextViews и изменить свои тексты.

Смежные вопросы