package com.example.administrator.jindutiao;
import android.app.Activity;
import android.databinding.DataBindingUtil;
import android.graphics.drawable.ClipDrawable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.SeekBar;
import com.example.administrator.jindutiao.databinding.ActivityMainBinding;
public class MainActivity extends Activity {
ActivityMainBinding dv;
private int myProgress=60;
int max=80;
int min=20;
// ClipDrawable clipDrawable;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.activity_main);
dv= DataBindingUtil.setContentView(this,R.layout.activity_main);
//设置进度条且是从20-80
dv.seekBar.setMax(max-min);
dv.seekBar.setProgress(myProgress-20);
dv.progressShow.setText(myProgress+"");
dv.seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
//通知进度已经被修改。客户端可以使用fromUser参数区分用户触发的改变还是编程触发的改变。
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
dv.progressShow.setText(progress+20+"");
myProgress=progress+20;
}
//通知用户已经开始一个触摸拖动手势。客户端可能需要使用这个来禁用seekbar的滑动功能。
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
//通知用户触摸手势已经结束。客户端可能需要使用这个来启用seekbar的滑动功能。
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
dv.dreceass.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
myProgress--;
dv.seekBar.setProgress(myProgress-20);
dv.progressShow.setText(myProgress+"");
}
});
// clipDrawable= (ClipDrawable) dv.clipIv.getDrawable();
dv.add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
myProgress++;
dv.seekBar.setProgress(myProgress-20);
dv.progressShow.setText(myProgress+"");
}
});
}
}
布局文件如下:
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical"
>
<ScrollView
android:id="@+id/scrollow"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/color_f0">
<LinearLayout
android:id="@+id/deal_detail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorThemeWhite"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorThemeWhite"
>
<TextView
android:id="@+id/zhi_sun_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18dip"
android:layout_centerHorizontal="true"
android:text="止损:"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18dip"
android:layout_toRightOf="@+id/zhi_sun_txt"
android:textColor="@color/green"
android:text="不限"
/>
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="35dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="10dip"
android:layout_marginRight="16dip"
android:gravity="center_vertical"
android:background="@drawable/shape_co_5_st_e0"
android:orientation="horizontal">
<FrameLayout
android:id="@+id/dreceass"
android:layout_width="35dp"
android:layout_height="match_parent">
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_gravity="center"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="@color/color_cb" />
</FrameLayout>
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="@color/color_e0" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dip"
android:text="不限"
android:gravity="center"
android:textColor="@color/color_7f"
android:textSize="14dip" />
<SeekBar
android:id="@+id/seek_bar"
android:layout_width="0dip"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:maxHeight="2dip"
android:thumbOffset="0dip"
android:background="@color/transparent"
android:progressDrawable="@drawable/seek_bar_bg"
android:thumb="@drawable/seek_bar_thum"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dip"
android:text="80点"
android:gravity="center"
android:textColor="@color/color_7f"
android:textSize="14dip" />
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="@color/color_e0" />
<FrameLayout
android:id="@+id/add"
android:layout_width="35dp"
android:layout_height="match_parent"
>
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_gravity="center"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="@color/color_cb" />
<View
android:layout_width="2dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:background="@color/color_cb" />
</FrameLayout>
</LinearLayout>
<LinearLayout
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="35dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="10dip"
android:layout_marginRight="16dip"
android:layout_marginBottom="10dip"
android:gravity="center_vertical"
android:layout_gravity="center_vertical"
android:background="@drawable/shape_co_5_st_e0"
android:orientation="horizontal">
<FrameLayout
android:id="@+id/zhi_sun_decrease"
android:layout_width="35dp"
android:layout_height="match_parent">
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_gravity="center"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="@color/color_cb" />
</FrameLayout>
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="@color/color_e0" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dip"
android:text="不限"
android:gravity="center"
android:textColor="@color/color_7f"
android:textSize="14dip" />
<SeekBar
android:id="@+id/zhi_sun_seek_bar"
android:layout_width="0dip"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:maxHeight="1dip"
android:thumbOffset="0dip"
android:background="@color/transparent"
android:progressDrawable="@drawable/seek_bar_bg_red"
android:thumb="@drawable/seek_bar_thum_red"
/>
<TextView
android:id="@+id/zhi_sun_show_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dip"
android:text="--"
android:gravity="center"
android:textColor="@color/color_7f"
android:textSize="14dip" />
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="@color/color_e0" />
<FrameLayout
android:id="@+id/zhi_sun_add"
android:layout_width="35dp"
android:layout_height="match_parent">
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_gravity="center"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="@color/color_cb" />
<View
android:layout_width="2dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:background="@color/color_cb" />
</FrameLayout>
</LinearLayout>
<TextView
android:id="@+id/progress_show"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dip"
android:layout_marginLeft="5dip"
android:text="--"
android:gravity="center"
android:textColor="@color/color_7f"
android:textSize="24dip" />
</LinearLayout>
</ScrollView>
</RelativeLayout>
</layout>
seek_bar_bg文件如下
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!--灰色的进度条,也就是相当于背景-->
<item android:id="@android:id/background">
<shape>
<corners android:radius="5dip" />
<!-- angle 是角度 -->
<gradient
android:angle="270"
android:centerColor="@color/color_7f_trans_7f"
android:centerY="0.75"
android:endColor="@color/color_7f_trans_7f"
android:startColor="@color/color_7f_trans_7f" />
</shape>
</item>
<!--拖动的第一进度条 -->
<!--由于进度条拖动的时候颜色与没有拖动所占有的颜色不一样,所以需要clip(裁剪)属性来设置,不然就没有颜色之间的差异 -->
<item android:id="@android:id/progress">
<clip>
<shape>
<corners android:radius="1dip" />
<gradient
android:angle="270"
android:centerColor="@color/green"
android:centerY="0.75"
android:endColor="@color/green"
android:startColor="@color/green" />
</shape>
</clip>
</item>
<!-- 第二进度条 -->
<!-- <item android:id="@android:id/secondaryProgress">
<clip>
<shape>
<corners android:radius="5dp" />
<gradient
android:angle="270"
android:centerColor="#545454"
android:centerY="0.75"
android:endColor="#545454"
android:startColor="#545454" />
</shape>
</clip>
</item> -->
</layer-list>
seek_bar_thum文件如下:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- 按下状态-->
<item
android:state_focused="true"
android:state_pressed="true"
android:drawable="@drawable/circle" />
<!-- 普通无焦点状态 -拖动按钮-->
<item
android:state_focused="false"
android:state_pressed="false"
android:drawable="@drawable/circle" />
<!-- 有焦点状态-->
<item
android:state_focused="true"
android:state_pressed="false"
android:drawable="@drawable/circle" />
<!-- 有焦点 -->
<item
android:state_focused="true"
android:drawable="@drawable/circle"/>
</selector>
circle文件如下:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:shape="oval">
<!--<stroke-->
<!--android:width="1dp"-->
<!--android:color="@color/custom_color"-->
<!--tools:targetApi="ice_cream_sandwich" />-->
<!--<corners android:radius="8dp" />-->
<size
android:width="15dp"
android:height="15dp" />
<solid android:color="@color/green"/>
</shape>
效果图如下:


1836

被折叠的 条评论
为什么被折叠?



