2014年8月14日木曜日

【アプリ開発】ProgressBarの色

今回プログレスバーの色の設定で少し戸惑ったため処理方法を書き留めておきます。


ProgressBarの色の設定方法

プログレスバーの色を変更して表示するための方法です。

 <!-- 読込中表示プログレスバー -->
 <ProgressBar
         android:id="@+id/loadingProgress"
         style="?android:attr/progressBarStyleHorizontal"
         android:progressDrawable="@drawable/ic_progress_green"
         android:layout_width="match_parent"
         android:layout_height="3dp"/>


<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
 <item android:id="@android:id/background">
     <shape>
  <corners android:radius="5dip" />
  <gradient
   android:startColor="#000000"
   android:centerColor="#000000"
   android:centerY="0.5"
   android:endColor="#000000"
   android:angle="270"
  />
  </shape>
 </item>
 <item android:id="@android:id/progress">
  <clip>
  <shape>
  <corners android:radius="5dip" />
  <gradient
   android:startColor="@color/holo_green_dark"
   android:centerColor="@color/holo_green_light"
   android:centerY="0.5"
   android:endColor="@color/holo_green_dark"
   android:angle="270"
  />
  </shape>
  </clip>
 </item>
</layer-list>




ProgressBarのアニメーション表示

プログレスバーを読み込み中のようにアニメーション表示するための方法です。


     <!-- 読込中表示プログレスバー -->
     <ProgressBar
         android:id="@+id/loadingProgress"
         android:layout_width="match_parent"
         android:layout_height="3dp"
         android:indeterminateDrawable="@drawable/ic_progress_indeterminate_green" />




<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
    android:oneshot="false" >
    <item android:duration="200">
        <shape android:shape="rectangle" >
            <gradient
                android:angle="180"
                android:centerY="1.0"
                android:endColor="@color/holo_green_dark"
                android:centerColor="@color/holo_green_light"
                android:startColor="@color/holo_green_dark"
                android:type="linear" />
        </shape>
    </item>
    <item android:duration="50">
        <shape android:shape="rectangle" >
            <gradient
                android:angle="180"
                android:centerY="0.8"
                android:endColor="@color/holo_green_dark"
                android:centerColor="@color/holo_green_light"
                android:startColor="@color/holo_green_dark"
                android:type="linear" />
        </shape>
    </item>
    <item android:duration="50">
        <shape android:shape="rectangle" >
            <gradient
                android:angle="180"
                android:centerY="0.6"
                android:endColor="@color/holo_green_dark"
                android:centerColor="@color/holo_green_light"
                android:startColor="@color/holo_green_dark"
                android:type="linear" />
        </shape>
    </item>
    <item android:duration="50">
        <shape android:shape="rectangle" >
            <gradient
                android:angle="180"
                android:centerY="0.4"
                android:endColor="@color/holo_green_dark"
                android:centerColor="@color/holo_green_light"
                android:startColor="@color/holo_green_dark"
                android:type="linear" />
        </shape>
    </item>
    <item android:duration="50">
        <shape android:shape="rectangle" >
            <gradient
                android:angle="180"
                android:centerY="0.2"
                android:endColor="@color/holo_green_dark"
                android:centerColor="@color/holo_green_light"
                android:startColor="@color/holo_green_dark"
                android:type="linear" />
        </shape>
    </item>
    <item android:duration="70">
        <shape android:shape="rectangle" >
            <gradient
                android:angle="180"
                android:centerY="0.0"
                android:endColor="@color/holo_green_dark"
                android:centerColor="@color/holo_green_normal"
                android:startColor="@color/holo_green_dark"
                android:type="linear" />
        </shape>
    </item>

    <item android:duration="100">
        <shape android:shape="rectangle" >
            <gradient
                android:angle="180"
                android:centerY="0.2"
                android:endColor="@color/holo_green_dark"
                android:centerColor="@color/holo_green_normal"
                android:startColor="@color/holo_green_dark"
                android:type="linear" />
        </shape>
    </item>
    <item android:duration="100">
        <shape android:shape="rectangle" >
            <gradient
                android:angle="180"
                android:centerY="0.4"
                android:endColor="@color/holo_green_dark"
                android:centerColor="@color/holo_green_normal"
                android:startColor="@color/holo_green_dark"
                android:type="linear" />
        </shape>
    </item>
    <item android:duration="100">
        <shape android:shape="rectangle" >
            <gradient
                android:angle="180"
                android:centerY="0.6"
                android:endColor="@color/holo_green_dark"
                android:centerColor="@color/holo_green_normal"
                android:startColor="@color/holo_green_dark"
                android:type="linear" />
        </shape>
    </item>
    <item android:duration="100">
        <shape android:shape="rectangle" >
            <gradient
                android:angle="180"
                android:centerY="0.8"
                android:endColor="@color/holo_green_dark"
                android:centerColor="@color/holo_green_normal"
                android:startColor="@color/holo_green_dark"
                android:type="linear" />
        </shape>
    </item>
    <item android:duration="100">
        <shape android:shape="rectangle" >
            <gradient
                android:angle="180"
                android:centerY="1.0"
                android:endColor="@color/holo_green_dark"
                android:centerColor="@color/holo_green_normal"
                android:startColor="@color/holo_green_dark"
                android:type="linear" />
        </shape>
    </item>

</animation-list>

2014年7月16日水曜日

【アプリ開発】TextViewの小ネタ(Tips)

TextViewの便利な設定やちょっとした小技をまとめていきます☆



URLやメールアドレスの自動リンク設定


    // 自動的にリンクを生成するように設定
    TextView csLinkedTextView = new TextView(this);
    csLinkedTextView.setText("URL:http://www.takahara-books.com/Android/");
    csLinkedTextView.setAutoLinkMask(Linkify.ALL);




フォントの指定


    // ビューに表示するフォントを指定
    TextView csFontTextView = new TextView(this);
    csFontTextView.setText("サンプル");
    csFontTextView.setTypeface(Typeface.SERIF, Typeface.BOLD_ITALIC);




自動補完の機能追加


    // 候補に表示される文字列
    String[] strAutoWordlist = new String[]{
        "Cupcake",
        "Cute",
        "Donut",
        "Eclair",
        "Froyo",
        "Gingerbread",
        "Honeycomb",
        "IceCreamSandwich",
        "Kitkat"
    }

    // アダプタを作成
    ArrayAdapter adapterAuto = new ArrayAdapter(
        this,
        android.R.layout.simple_dropdown_item_1line,
        strAutoWordlist
    );

    // AutoCompleteTextViewインスタンスを作成
    AutoCompleteTextView csAutoCompTextView = new AutoCompleteTextView(this);

    // アダプタをセット
    csAutoCompTextView.setAdapter(adapterAuto);




2014年6月13日金曜日

【アプリ活用】DevAppsDirect

icon DevAppsDirect

GitHubなんかで公開されている数多くのライブラリのサンプルを実際にアプリ内でダウンロードして実行できるデモアプリです。全部確認してみましたが、自分のアプリにも取り入れたい物が結構ありましたので、いずれ使っていきたいですね。

動作している端末によっては、デモの内起動できないものもありますが、デモ自体は随時更新されているので、日々新しいライブラリを確認することができてとても便利です☆


今回その中で、簡単に組み込めそうで今後使っていきたいと思っているものを紹介していきます(^O^)/




①PagedDragDropGrid


このライブラリはグリッドで画像等を表示し、アイテムを長押しするとそのアイテムを別な場所に
移動することができます。自動で並び替えをせず、ユーザーが好きに並び順を決めたい場合に
使えるかと思います。

データフォルダでは自動で並び替えているため使いドコロが今のところありませんが、
いずれ新しいアプリででも使用してみたいライブラリです(^^)


対応OS:Android2.2(API 8)以上



②Showcase View




最近色々なアプリでみかけるようになったライブラリですね。
ヘルプやチュートリアルなどで、操作の説明するときなどに使われています。
ボタンを強調してテキストで説明したり、アニメーションによる解説、強調位置を移動させて順々に説明することができます。

使える用途も多いかと思いますし、初回のチュートリアルなんかで丁寧に解説したいときに取り入れていきたいなと思っています。

できれば説明なしに直感で使えるアプリにできることが理想ですけど、
機能を増やすとどうしても説明が必要になってきますしね(^^;



③ArchMenu


画面上には2つのボタンがありますが、左上のボタンをタッチするとボタンからみぎにメニューが飛び出します。
その下のボタンをタッチすると右上にメニューがそれぞれ飛び出してきます。

NEXUS5では解像度の関係でメニューが小さく表示されてしまっているようですが、調整できれば
ビジュアル的にもよさ気なので、ゲーム等のアプリを作った際には試してみたいライブラリです。

色々ライブラリを見つけてて思うのですが、使いドコロを考えるのが難しいですよね(^^;

対応OS:Android 2.0以上