我的Activity中有两个SeekBars
,但现在我想把SeekBar
的值差大于等于1的约束放在一起。我怎样才能做到这一点?这是我的xml文件:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Rs. 0L"
android:id="@+id/min_budget"
/>
<SeekBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/budget_min_seekbar"
/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="No Limit"
android:id="@+id/max_budget"
/>
<SeekBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/budget_max_seekbar"
/>
</LinearLayout>
和相应的Java文件如下所示:
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_budget_filter, container, false);
SeekBar max_budget_sbar = (SeekBar) rootView.findViewById(R.id.budget_max_seekbar);
TextView max_budget_tv = (TextView) rootView.findViewById(R.id.max_budget);
SeekBar min_budget_sbar = (SeekBar) rootView.findViewById(R.id.budget_min_seekbar);
TextView min_budget_tv = (TextView) rootView.findViewById(R.id.min_budget);
AndroidSeekBar set_max= new AndroidSeekBar(max_budget_sbar, max_budget_tv,1);
AndroidSeekBar set_min= new AndroidSeekBar(min_budget_sbar, min_budget_tv,1);
return rootView;
}
AndroidSeekBar
类根据SeekBar
的位置设置texviews的值,并具有以下代码:
.....
public AndroidSeekBar(SeekBar id1, TextView textid,int type){
/** Called when the activity is first created. */
PRICEbar = id1; // make seekbar object
SeekValue = textid;
int progress = PRICEbar.getProgress();
PRICEbar.setTag(String.valueOf(type));
PRICEbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener(){
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
int type=Integer.parseInt(seekBar.getTag().toString());
if(type==1){
if(progress>95){
SeekValue.setText("No Limit");
}
else{
float value = (float)(progress*2/10);
SeekValue.setText("Rs. "+ String.valueOf(progress) + " L");
}
}
}
....
}