2015-08-22 3 views
0

Я хотел бы сделать мой виджет максимально согласованным с помощью виджета календаря Google. См. Ссылку на изображение (извините, у меня недостаточно репутации, чтобы вставить изображение). Цвета используются для определения того, сколько места занимает каждый элемент.Как заставить мой виджет выглядеть как виджет календаря Google?

image link

widget.xml

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:padding="@dimen/widget_margin"> 

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

    <RelativeLayout 
    android:id="@+id/headerLayout" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentTop="true" 
    android:paddingLeft="10dp" 
    android:paddingRight="10dp" 
    android:background="@drawable/appwidget_dark_bg_clickable"> 

    <LinearLayout 
     android:id="@+id/configureButton" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:layout_alignParentTop="true" 
     android:layout_alignParentLeft="true" 
     android:layout_toLeftOf="@+id/refreshButton" 
     android:layout_centerInParent="true" 
     android:layout_gravity="center_vertical" 
     android:background="#aa999966"> 

     <TextView 
     android:id="@+id/headerTextView" 
     android:clickable="true" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:gravity="top|left" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" 
     android:layout_above="@+id/footerTextView" 
     style="@style/headerTextStyle" 
     android:text="Channel"/> 

     <TextView 
     android:id="@+id/footerTextView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:gravity="bottom|left" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentLeft="true" 
     style="@style/footerTextStyle" 
     android:text="last update: just started"/> 
    </LinearLayout> 

    <ImageView 
     android:id="@+id/refreshButton" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:background="#aa8888bb" 
     android:src="@drawable/ic_refresh_white_36dp" 
     android:layout_alignParentRight="true" 
     android:layout_centerInParent="true" 
     android:layout_gravity="center_vertical"/> 
    </RelativeLayout> 

    <GridView 
    android:id="@+id/fieldsGridView" 
    android:numColumns="1" 
    android:gravity="center" 
    android:stretchMode="columnWidth" 
    android:background="@color/white" 
    android:layout_below="@+id/headerLayout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:padding="8dp" 
    android:clipToPadding="false"> 
    </GridView> 

    <TextView 
     android:id="@+id/empty_view" 
     android:background="@color/white" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_alignParentBottom="true" 
     android:layout_below="@+id/headerLayout" 
     android:gravity="center" 
     style="@style/emptyTextStyle" 
     android:text="Empty"/> 

</RelativeLayout> 
</FrameLayout> 

list_item.xml

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="@drawable/appwidget_dark_bg_clickable" 
    android:paddingLeft="8dp" 
    android:paddingRight="8dp"> 
    <TextView 
     android:id="@+id/fieldNameTextView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:gravity="center_vertical|left" 
     android:layout_alignParentLeft="true" 
     android:layout_centerInParent="true" 
     android:layout_toLeftOf="@+id/fieldValueTextView" 
     android:background="#aaff0000" 
     style="@style/fieldNameTextStyle"/> 
    <TextView 
     android:id="@+id/fieldValueTextView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:layout_centerInParent="true" 
     android:gravity="center_vertical|right" 
     android:background="#aa00ff00" 
     style="@style/fieldValueTextStyle"/> 
</RelativeLayout> 

Мои вопросы:

  1. Как я могу сделать нижнюю часть моего заголовка прямым прямоугольником? Нужно ли мне модифицировать девять патчей? Я использую шаблон Google. Есть ли у меня шансы найти png, который они используют для календаря?
  2. Как уменьшить дополнительное пространство в элементе списка? Есть какая-то прокладка, даже если я использую только android:paddingLeft="8dp" и android:paddingRight="8dp"
  3. Как увеличить границу между двумя списками?

Благодаря

+0

App виджет, который выглядит как Android календарь описано здесь: https: //pristalovpavel.wordpress.com/2015/10/27/how-to-create-calendar-like-app-widget-with-optimized-i Маги-в-лист / – anil

ответ

0

Ответ на свой вопрос после некоторых исследований:

Результат, see link

1. Форма заголовка

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

widget_header_background.xml в разрешении/вытяжке

<?xml version="1.0" encoding="utf-8"?> 

<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
    <corners 
     android:topLeftRadius="3dp" 
     android:topRightRadius="3dp"/> 
    <solid android:color="#ffff0000"/> 
    <stroke 
      android:color="#ffff0000" 
      android:width="1dp"/> 
</shape> 

использованием android:background="@drawable/widget_header_background" в widget.xml

2. Дополнительное место в ListView

Используйте другой рисуем форму

widget_header_background.xml

<?xml version="1.0" encoding="utf-8"?> 

<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
    <corners 
     android:radius="3dp"/> 
    <solid android:color="@color/grey"/> 
    <stroke 
      android:color="@color/grey" 
      android:width="1dp"/> 
</shape> 

3. ListView делитель пространства

Добавить

android:divider="#ffffff" 
android:dividerHeight="4dp" 

в вашем listview