2012-08-12 2 views
8

내가이 슬라이더 같은 것을 만들고 싶었 전환? 나는 안드로이드 개발에 익숙하지 않으므로 최대한 많은 예제 코드를 포함 시키십시오. 매우 도움이 될 것입니다.안드로이드 멀티 상태

+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); 
    } 
} 

출력 :

screenshot of sliders

1

이것에 대한 좋은 도서관이있다 : android-comboseekbar. 사용하거나 작동 방법을 확인하십시오.

화면 Screen

+0

이 링크는 질문에 대답 할 수 있지만 여기에 답의 핵심 부분을 포함시키고 참고. 링크 된 페이지가 변경되면 링크 전용 답변이 유효하지 않게 될 수 있습니다. - [From Review] (리뷰/저품절 게시물/17377976) –

관련 문제