AndroidのRelativeLayoutとは
RelativeLayoutとは
Android Studioで画面レイアウトを編集する際の部品配置方式のひとつで、Viewを他のViewとの相対的な位置関係で記述する方式である。(ViewとはマイクロソフトのVisual Studioで言うとコントロールのこと。)
android:layout_below="@id/text_top_left"
のように、
・隣のViewの隣接面(上下左右)を表す文字列(例:layout_below)
・隣のViewのID
を指定するようになっている。
隣接面を表す文字列には、layout_toEndOfとlayout_toStartOfという紛らわしいものがあるが、これらは、文字を左から右に読む言語の場合は、それぞれ、layout_toRightOf、layout_toLeftOfと同じ効果をもたらす。
<感想>
アンドロイドスタジオで使われる用語が、マイクロソフトの開発ツールの用語と違いすぎる。機能上そうならざるを得ないのか、それとも最初から統一する気がないのか。コントロールをビューと言ってみたり、プロパティをアトリビュートと言ってみたり。日本語と英語、マイクロソフトとアンドロイド、いろんな障壁があって学習がなかなか進まない。┐(´д`)┌ヤレヤレ
```java
<?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="match_parent"
android:padding="16dp">
<TextView
android:id="@+id/text_top_left"
android:layout_width="159dp"
android:layout_height="wrap_content"
android:textSize="30sp" />
<TextView
android:id="@+id/text_top_right"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/text_top_left"
android:layout_marginLeft="10dp"
android:textSize="30sp" />
<TextView
android:id="@+id/text_bottom_left"
android:layout_width="159dp"
android:layout_height="wrap_content"
android:layout_below="@id/text_top_left"
android:layout_marginTop="10dp"
android:textSize="30sp" />
<TextView
android:id="@+id/text_bottom_right"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/text_top_right"
android:layout_toRightOf="@id/text_top_left"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:textSize="30sp" />
</RelativeLayout>
```
Pythonを対話モードで起動する際の作業を自動化するバッチコマンド(Windows 10)
Windows10で、Pythonを対話モードで起動する際に行う面倒な作業を自動化するバッチコマンドを紹介したいと思います。
・管理者権限でコマンドプロンプトを起動
・カレントディレクトリ移動
・文字コード設定
・py.exe(Pythonランチャー)を実行
といった作業を、すべてバッチコマンドでできるようにしています。
ファイルの拡張子をbatとして保存してお使いください。
@echo off powershell -NoProfile start-process cmd -ArgumentList '/k "cd /d %CD% & chcp 65001 & py -3.9"' -verb runas
備考
start-process :
PowerShellのコマンドレットで、他プロセスを起動するときに指定します。ここでは、他プロセスとして、cmd(コマンドプロンプト)を指定しています。
-ArgumentList :
start-processのオプションです。他プロセスに与える引数を指定します。
/K :
コマンドプロンプトのオプションスイッチで、後に続くコマンドを実行し、そのままコマンドプロンプトを終了しない場合に使います。
-verb runas :
start-processのオプションです。他プロセスを管理者権限で起動するときに指定します。