Android アプリのレイアウトに取り組んでいますが、すべてのボタンが Eclipse の列に自動的に固定されていることがわかりました。リンク先のアプリのように希望の位置にするにはどうすればいいですか?? ありがとう
http://www.dcemu.co.uk/vbulletin/threads/335622-Android-oscilloscope
Android アプリのレイアウトに取り組んでいますが、すべてのボタンが Eclipse の列に自動的に固定されていることがわかりました。リンク先のアプリのように希望の位置にするにはどうすればいいですか?? ありがとう
http://www.dcemu.co.uk/vbulletin/threads/335622-Android-oscilloscope
RelativeLayout
ファイルの代わりにLinearLayout
使用できmain.xml
ます。このレイアウトでは、レイアウト内の任意の場所にコンポーネントを配置できますが、コンポーネントは相互に配置されrelatively
ます。レイアウトの組み合わせを使用して、ビューを健全に見せることができます。また、レイアウトの向き、つまり垂直または水平のいずれかを使用してみてください。
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
LinearLayout
それぞれが2つのボタンを含む複数の水平を含む垂直を持つことにより、2列のボタンを取得できLinearLayout
ます。ボタンの間隔を均等にするためにボタンに同じ重みを与え、ボタンがすっきりと見えるように余裕を持たせます。
例えば
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="Button 1" />
<Button
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="Button 2" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="Button 3" />
<Button
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="Button 4" />
</LinearLayout>
</LinearLayout>
または、列が非常に長くなる場合は、2つの垂直線形レイアウトを含む水平線形レイアウトを使用して、それらにボタンを追加できます。
またはTableLayout
、2列のaを使用してTableRows
、ボタンを含めることもできます(通常、テーブルレイアウトの操作は難しいと思いますが、おそらくそれは私だけです)。
グラフィカルエディターをいじくり回すよりも、Eclipseでxmlを作成する方が簡単だと思います。その後、グラフィカルエディターに何度も切り替えて、希望どおりに表示されることを確認します。いくつかのレイアウト例をオンラインで見て回れば、すぐにアイデアが浮かびます。
そのレイアウトを正確にエミュレートするにはRelativeLayout
、mihailが提案するように開始し、それを使用して他のレイアウト(ボタン付きの線形レイアウトなど)とビューを配置します。