2012-08-12 4 views
8

を切り替える: enter image description hereAndroidのマルチステートは、私は、このスライダーのようなものを作成したい

を3つのステートスライダーを定義するには、Androidでの方法は何ですか?私はアンドロイドの開発に新しいので、できるだけ多くのサンプルコードを含めてください、それは非常に便利です。

+0

あなたはまだこの問題を解決することができたことがありますか?はいの場合は、あなたの答えを投稿してください! – Milan

+0

私はあなたが必要とするのはカスタムRatingBarだと思う:http://www.b2creativedesigns.com/ratingbar.php –

答えて

5

単純な例は、次のコードのようになります。あなたは少しグラフィックスで遊ぶことができ、あなたはあなたが望むものを得るでしょう。

レイアウト/ main.xml

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/TableLayout1" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:padding="10dp" > 

    <include 
     android:id="@+id/tableRow1_ref" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     layout="@layout/description" /> 

    <SeekBar 
     android:id="@+id/seekBar1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="10dp" 
     android:layout_marginTop="10dp" 
     android:max="100" /> 

    <include 
     android:id="@+id/tableRow1_ref" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     layout="@layout/description" /> 

    <SeekBar 
     android:id="@+id/seekBar2" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="10dp" 
     android:max="100" /> 

</TableLayout> 

レイアウト/ description.xml

<?xml version="1.0" encoding="utf-8"?> 
<TableRow xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/tableRow1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" > 

    <TextView 
     android:id="@+id/textView1" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:gravity="left" 
     android:paddingLeft="5dp" 
     android:text="@string/kid" /> 

    <TextView 
     android:id="@+id/textView2" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:gravity="center" 
     android:text="@string/adult" /> 

    <TextView 
     android:id="@+id/textView3" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:gravity="right" 
     android:paddingRight="5dp" 
     android:text="@string/senior" /> 

</TableRow> 

MainActivity.java

package com.test.Slider; 

import android.os.Bundle; 
import android.support.v7.app.ActionBarActivity; 
import android.widget.SeekBar; 
import android.widget.SeekBar.OnSeekBarChangeListener; 

public class MainActivity extends ActionBarActivity 
     implements OnSeekBarChangeListener{ 

    SeekBar sb1, sb2; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     sb1 = (SeekBar)findViewById(R.id.seekBar1); 
     sb2 = (SeekBar)findViewById(R.id.seekBar2); 

     sb1.setOnSeekBarChangeListener(this); 
     sb2.setOnSeekBarChangeListener(this); 
    } 

    @Override 
    public void onProgressChanged(SeekBar seekBar, int progress, 
      boolean fromUser) { 
     // we don't need it 
    } 

    @Override 
    public void onStartTrackingTouch(SeekBar seekBar) { 
     // we don't need it  
    } 

    @Override 
    public void onStopTrackingTouch(SeekBar seekBar) { 
     int mProgress = seekBar.getProgress(); 
     if(mProgress > 0 & mProgress < 26) { 
      seekBar.setProgress(0); 
     } else if(mProgress > 25 & mProgress < 76) { 
      seekBar.setProgress(50); 
     } else seekBar.setProgress(100); 
    } 
} 

出力:android-comboseekbar

screenshot of sliders

1

このための良いライブラリがあります。 それを使用するか、それがどのように機能するかを見てください。

画面 Screen

+0

このリンクは質問に答えるかもしれないが、答えの本質的な部分をここに入れて、参照。リンクされたページが変更された場合、リンクのみの回答は無効になります。 - [レビューの投稿](/レビュー/低品質の投稿/ 17377976) –

関連する問題