LoginSignup
0
0

More than 5 years have passed since last update.

Androidアプリ系メモ

Last updated at Posted at 2015-05-08

AndroidStudioやAndroidアプリのUIデザイン・コーディングに関する情報をメモ。

http://andante.in/i/
http://android.keicode.com/basics/
http://techbooster.org/android/ui/606/


Androidアプリの仕組み

各ディレクトリ、ファイルについて

[ マニフェストファイル(AndroidManifest.xml) ]
そのアプリの名前やアイコン、機能面についての様々な情報を書いておく為のファイル
■Activity
※下記サイトの説明がとてもわかりやすかった
http://nobuo-create.net/manifest/

ショートカット

個人的に使用頻度高いor高そうなものを抜粋。

行選択 cmd+shift+矢印キー
行頭へor行末へ cmd+矢印キー
タブごとに移動 option+矢印キー
ソースコードフォーマット cmd + option + L
検索 cmd + option + L
ファイル名検索 cmd + shift + O
■参考URL

Android Studio ショートカットキーリスト for Mac
http://qiita.com/Tazake/items/5c725a8b68d13271d43d

Android Studio よく使うショートカットキー
http://oki2a24.com/2015/03/26/android-studio-keymap/


◼︎インストール、設定時の参考URL

http://www.gaprot.jp/pickup/android-ide/vol3/
http://qiita.com/ryo0301/items/3c9a02e03b4e9a41f576

・【Android Studio】JDKのバージョンが合わない場合の対処法
http://idea-cloud.com/dev/jdk_version.html
・Javaダウンロードサイト
http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html

◼︎Javaで JDK7を入れた後も7ないよといわれた時
・Java6と7だと、インストールされた場所が違うパターン
 > Android Studioで下記設定を変更
※参考URL
http://qiita.com/hardreggaecafe/items/3d193878a54059a78124

■GUIの見方
Gradle Console ここでエラー内容の確認ができそう

javaのバージョンと格納場所確認のコマンド
/usr/libexec/java_home -V

エミュレーターとうまく連携しない時

参考URL
http://stackoverflow.com/questions/27690431/configure-intellij-idea-such-that-source-detected-in-git-but-unregistered-vcs-ro


Androidサイト。レイアウトやらDevやらいろいろのってる
http://developer.android.com/index.html

XMLとレイアウト
http://yul-dev.hatenablog.com/entry/2014/12/07/192015

参考
http://kuwalab.hatenablog.jp/entry/20110101/p1
参考UI
http://itpro.nikkeibp.co.jp/article/COLUMN/20120113/378483/
http://blog.v-colors.com/2015-android-material-design-document.html

画面の距離は dp
fontの大きさは sp
※様々な種類のサイズがあるので、それに対応させる設定のよう

使いやすくするために(パーツごとの管理)

・使いまわすモノは各パーツファイルごとにxmlファイルを作成して管理

※参考URL
http://qiita.com/konifar/items/68f196dc7acacfcf40cf

AndroidStudioで新規xmlファイルを作成する場合

filename
GUIのプロジェクト(左のサイドバー)で、作成したxmlファイルに「(Idltr)」が表記されている
→ 左から右に表記される(left to rightの略)

※参考URL
http://www.atmarkit.co.jp/fwcr/design/cssref/layout/direction.html

Javaについて

onCreate

アクティビティが作られた時によばれるメソッド


AndroidのUIガイドラインについて

AndroidのダメなUX、UIパターン(Googleのエンジニアさんが動画で詳しく紹介してくれています)
http://appstars.jp/archive/114

画像サイズまとめ
http://www.webtech.co.jp/blog/products/optpix-imesta/6915/
http://blog.excite.co.jp/spdesign/19798730/


レイアウト

CSS的な使い方

パーツ単位で格納したり、色、線などCSS的な使用を行う

(1)styleの設定をする

valuesの中のstyles.xmlに書いていく(values内に別途作成してもOK)
resourcesタグの中にstyleタグを使用して、それぞれstyleを設定していく。

values/styles.xml
<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
    </style>

    <style name="Sample001">
        <item name="android:layout_width">match_parent</item>
        <item name="android:layout_height">match_parent</item>
        <item name="android:background">#dddddd</item>
        <item name="android:textColor">#666666</item>
    </style>

</resources>

(2)画面用xmlファイルに反映する

layout/main.xml
<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:paddingLeft="@dimen/activity_horizontal_margin"
                android:paddingRight="@dimen/activity_horizontal_margin"
                android:paddingTop="@dimen/activity_vertical_margin"
                android:paddingBottom="@dimen/activity_vertical_margin"
                tools:context=".MainActivity">

    <TextView
        android:text="@string/hello_world"
        style="@style/Sample001"/>

</RelativeLayout>



レイアウトのプロパティ

Left align Right align Center align
layout_gravity center_vertical 上下中央に配置 ※gravityと間違えないように!
layout_width or layout_height fill_parent match_parentを同じ機能API Level 8から非推奨API Level 7以下をターゲットとしないのであればmatch_parentを使用
layout_width or layout_height match_parent fill_parentと同じ機能API Level 8から非推奨API Level 7以下をターゲットとしないのであればmatch_parentを使用

参考URL
https://github.com/mixi-inc/AndroidTraining/wiki/2.01.-%E3%82%A2%E3%83%97%E3%83%AA%E3%81%AE%E3%83%AC%E3%82%A4%E3%82%A2%E3%82%A6%E3%83%88%E4%BD%9C%E6%88%90


タイトルバーを非表示にする

デフォルトで入っているタイトルバーを非表示にする

AndroidManifest.xmlのapplicationに
「android:theme="@android:style/Theme.NoTitleBar”」 を仕込む
※仕込む際は初期設定で入っている「android:theme="@style/AppTheme”」を変更して設定

参考URL
https://akira-watson.com/android/theme-notitlebar.html


ListView

ListViewの表示

UIイメージ用に、view側だけ作成する為の方法。

追記:現状、下記サイトのやり方でできた
http://d.hatena.ne.jp/ats337/20110105/1294233336

※参考URL
http://d.hatena.ne.jp/androidprogram/20100628/1277685225

1)メインのxml(こんかいはactivity_main.xml)にListviewをセット

activity_main.xml
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:background="#f3f3f3ff”//仮背景色
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="16dp"
    android:orientation="vertical">

    <ListView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:entries="@array/test_array"/>

</LinearLayout>

2)strings.xmlに、ListView内に表示させたい文字をセット

strings.xml
<resources>
    <string name="app_name">TestProperty</string>

    <string name="hello_world">Hello world!</string>
    <string name="action_settings">Settings</string>

    <!-- ListView -->
    <string-array name="test_array">
        <item>あいうえお</item>
        <item>かきくけこ</item>
        <item>さしすせそ</item>
        <item>たちつてと</item>
        <item>なにぬねの</item>
        <item>はひふへほ</item>
        <item>まみむめも</item>
        <item>や ゆ よ</item>
        <item>らりるれろ</item>
        <item>わをん  </item>
    </string-array>
</resources>

3)Activity(今回はプロジェクト作成時のデフォルトの名前MainActivity.javaのまま作成)に
ListView内にstringの配列をセット
※すでに設置されているOncreateやonCreateOptionsMenu、onOptionsItemSelectedなどの
中ではなく、MainActivityクラスの直内に記載する

MainActivity.java
public class MainActivity extends Activity {

・・・
    //ListView セット用
    public class ListViewTest extends Activity {
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);

            setContentView(R.layout.activity_main);//(1)のxmlファイル名をlayout.以降に記載
        }
    }


}

ListViewのプロパティ

単純に行間の区切り線の色・太さを変える
android:divider="#000000"//色
android:dividerHeight="2sp"//太さ
http://blog.inoaki.com/2010/05/listview_317.html

行間の区切り線を消す
android:divider="@null"

取り急ぎ簡単にシャドウをつけたい時
android:elevation=""
※オートで"@dimen/activity_horizontal_margin"などが出る。
ただあくまで取り急ぎ用。精度は低いし使用可能がLollipopのみらしい


Spinner

Spinnerをviewに設置したい → プロトタイプで画面サイドだけ準備
→ Spinnerにサンプルの選択肢を入れたい + Spinner1 x Spinner2にしたい

※参考URL
親の配列をまずスピナーで表示→選択されたらその選択に応じて子スピナーの配列を動的に制御
http://thjap.org/android/apps/make_app/1488.html

※上記URLにでてくる「リソース」について
http://www.javadrive.jp/android/xml_layout/

参考URL
http://y-anz-m.blogspot.jp/2014/04/androidspinnerxml.html
追加参考URL
http://yan-note.blogspot.jp/2010/11/android-spinner.html

エラーメモ

◯エラー内容
the following classes could not be instantiated
◯解決策
http://taka-say.hateblo.jp/entry/2015/06/03/161003


その他もろもろ

AndroidStudioのショートカット

参考URL
http://qiita.com/stenpel/items/6a2bb5dbc0139477c40c

プラグインについて
http://gihyo.jp/dev/serial/01/android_studio/0043

Android Drawable Importer

プロジェクトの削除方法

close projectでプロジェクトを閉じる -> ディレクトリを削除する

SDKについて
ビルドする為に必要なもの。AndroidStudioにはAndroidStudio用のSDKが、例えばSublimeTextならSublimeTextのSDKがある。
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0