2014年7月8日火曜日

Androidアプリのパッケージ名を変更する方法

目次へ



プロジェクト作成時にcom.example.xxという名前のパッケージ名をつけておくと、禁止された名前のため、このアプリを公開できません。
そこで、すでに作成してしまったパッケージ名を変更する方法を書いておきます(ECLIPSEでの方法)
  1. srcフォルダ内のパッケージ名変更
  2. AndroidManifest.xmlを変更する
の2つです。


■■■■src内のパッケージ名変更■■■■

ECLIPSEのパッケージエクスプローラで、プロジェクトのsrcフォルダの中のパッケージ名を右クリックし、 [リファクタリング]-[名前変更]を順にクリックし、com.example.xx以外の名前を決めます。
これでsrc内のパッケージ名は変更できます。

■■■■AndroidManifest.xmlの変更■■■■

次はgenフォルダの中のパッケージ名を変更します。
これは、AndroidManifest.xml内で指定することにより、変更できます。
manifestタグの中のpackage=の値を上で変更したsrcのパッケージ名と同じものにして保存します


<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.xx"  ←この名前を変更する
    android:versionCode="1"
    android:versionName="1.0" >


この2つの操作でsrcとgenの中のパッケージ名が変更できます。
genの中には、もう一つ、android.support.xxxというパッケージがありますがそれはそのままでOKです。



これでapkファイルを作成し、アプリを公開すれば、パッケージ名でおこられることはありません。
アプリ公開の方法はこちら(Androidアプリを公開する)です。


にほんブログ村 IT技術ブログ IT技術メモへ
にほんブログ村

2014年7月5日土曜日

AndroidのLayout  RelativeLayout

目次へ



RelativeLayoutでは、その中に置く部品をParentあるいは、他の部品との位置でしめすことにより、レイアウトします。


■■■■ RelativeLayoutの例 ■■■■



次のような画面は下のようなレイアウトファイルを使いました。


レイアウトファイル

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

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:text="ボタン1" />
    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/button1"
        android:text="ボタン2" />
    <Button
        android:id="@+id/button3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:text="ボタン3" />
    <Button
        android:id="@+id/button4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:text="ボタン4" />
    <Button
        android:id="@+id/button5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toLeftOf="@id/button1"
        android:layout_alignParentTop="true"
        android:text="ボタン5" />
    <Button
        android:id="@+id/button6"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@id/button2"
        android:layout_below="@id/button2"
        android:text="ボタン6" />

</RelativeLayout>




Relative Layoutの属性まとめ
親コンテナを基準にする方法と、他の部品を基準にする方法があります。
属性意味
layout_alignParentTop true 親コンテナの上端に配置
layout_alignParentBottom true 親コンテナの下端に配置
layout_alignParentLeft true 親コンテナの左端に配置
layout_alignParentRight true 親コンテナの右端に配置
layout_centerHorizontal true 親コンテナの水平方向の中央に配置
layout_centerVertical true 親コンテナの垂直方向の中央に配置
layout_centerParent true 親コンテナの水平垂直の中心に配置
layout_below "@id/button1" button1というIDのコンポーネントの下に配置
layout_above "@id/button1" button1というIDのコンポーネントの上に配置
layout_toLeftOf "@id/button1" button1というIDのコンポーネントの左に配置
layout_toRightOf "@id/button1" button1というIDのコンポーネントの右に配置



にほんブログ村 IT技術ブログ IT技術メモへ
にほんブログ村