私は現在、タブの下にアンドロイド(3.1)のユーザーインターフェイスを実装しようとしています。しかし、私は私に合ったものを見つけることができなかったので、いくつかの方法があることを知っています、私はラジオボタンを使用しようとしています。考えられるのは、各タブはラジオボタン(現在はテキストなし)です。柔軟な幅を持つAndroidラジオボタン
レイアウトはこのように見えるようになっている:
画面の上部に来るフラグメントのコンテナとして機能するでframeLayoutがあります。
コンテナの下には、各ラジオボタンがタブとして機能する水平ラジオグループがあります。アクティブなタブ(ラジオボタン)は上部の他のタブと重なっているはずなので、どのタブがアクティブかはっきりしています。ラジオボタンがタブのように動作するように、私はandroid:button属性をstatelistdrawableに設定しました。 statelistdrawableには、アクティブ状態と非アクティブ状態の2つのイメージが含まれています(残念ながら、まだ画像を投稿できません)。 アクティブなタブのイメージが非アクティブなタブよりも大きいので、アクティブなタブ(またはラジオボタン)がタブの左側に重なるように、onClickListenerのbringToFront()メソッドを使用しました。そしてその権利。
マイレイアウトファイルは次のようになります。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<!-- container for the fragments -->
<FrameLayout
android:id="@+id/fragment_container"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffff"
android:layout_weight="0" />
<!-- container for the tabs realized with radio buttons -->
<RadioGroup
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:orientation="horizontal"
android:layout_weight="1" >
<!-- tabs -->
<RadioButton android:id="@+id/tab_1"
android:state_checked="false"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:button="@drawable/tab_button"
android:text="" />
<RadioButton android:id="@+id/tab_2"
android:state_checked="false"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:button="@drawable/tab_button"
android:text="" />
<RadioButton android:id="@+id/tab_3"
android:state_checked="false"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:button="@drawable/tab_button"
android:text="" />
<RadioButton android:id="@+id/tab_4"
android:state_checked="false"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:button="@drawable/tab_button"
android:text="" />
<RadioButton android:id="@+id/tab_5"
android:state_checked="false"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:button="@drawable/tab_button"
android:text="" />
</RadioGroup>
</LinearLayout>
とstatelistdrawable xmlファイルのようになります。私は設定していても
- :
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android" android:constantSize="false"> <item android:state_checked="false" android:drawable="@drawable/tab_inactive" /> <item android:state_checked="true" android:drawable="@drawable/tab_active" /> </selector>
は、残念ながら、私は2つの問題に遭遇しましたframelayoutのlayout_weightは0に、radiogroupのレイアウト重みは1を取り囲む線形レイアウト内の1に設定します2つ目は、framelayoutは画面全体を占めています。
- デバッグのためにframelayoutの高さを0に設定すると、タブが表示されます。しかし、幅に渡って均等に分布しているわけではありませんが、それらはお互いに重なり合い、一番左に絞られています。 ラジオボタンの幅を、非アクティブなタブに使用される画像の幅(px)に設定すると、タブは均等に配置されます。しかし、タブの1つをクリックしてタブ・イメージがアクティブ・タブのものに変わったとき、statelistdrawableのandroid:constantSize属性をfalseに設定しても、ボタンはボタンを右または左に重ねることはありませんそれを右にシフトさせます。
誰も、特に相対的な寸法を使用して、これらの問題の解決策を得ていますか?これは私の最初の投稿です。私の質問が精巧であるかどうか、十分に検討されていなければ、事前にお詫びします。私を信頼して、私は今、(例えば、絶対的な次元を使って)これらの問題を修正するために年齢を試しました。どんな助けでも大いに評価されるでしょう!
私は今、私の第2の問題の(非常にエレガントではない)解決策を見つけました。私はタブ(ラジオボタン)と、どのタブがアクティブであるかに応じて異なる状態に対してlevelListDrawableを使用するフラグメントの間にセパレーションバーを挿入しました。 最初の問題を解決するための最初の問題 – Schnodahipfe
を残します。http://stackoverflow.com/questions/1958388/android-simple-linearlayout-and-fill-parent-question – Schnodahipfe