这是我创建拇指的代码:
public voID setSeekbarThumb(int wIDth,int height,int rcolor,int gcolor,int bcolor){ ShapeDrawable thumb = new ShapeDrawable( new ovalShape() ); thumb.setIntrinsicHeight( height ); thumb.setIntrinsicWIDth( wIDth ); thumb.setBounds(new Rect(0,wIDth,height)); StateListDrawable states = new StateListDrawable(); states.addState(new int[] {androID.R.attr.state_pressed},thumb );//add to the state List with the state pressed thumb = new ShapeDrawable( new ovalShape() ); thumb.setIntrinsicHeight( height ); thumb.setIntrinsicWIDth( wIDth ); thumb.setBounds(new Rect(0,height)); states.addState(new int[] { },thumb );//add to the state List with no state seekbar.setThumb(states); seekbar.setThumbOffset(0); }
继承我创建条形码的代码:
public voID setSeekbarProgress(int wIDth,int bcolor){ GradIEntDrawable shape = new GradIEntDrawable(OrIEntation.BottOM_top,new int[]{color.WHITE,color.rgb(rcolor,gcolor,bcolor)}); shape.setCornerRadius(50); shape.setSize(wIDth,height); shape.setBounds(0,height); ClipDrawable clip = new ClipDrawable(shape,Gravity.left,ClipDrawable.HORIZONTAL); shape = new GradIEntDrawable(OrIEntation.BottOM_top,getResources().getcolor(R.color.Dimgray)}); shape.setCornerRadius(50);//change the corners of the rectangle shape.setSize(wIDth,height); LayerDrawable mylayer= new LayerDrawable(new Drawable[]{shape,clip,}); seekbar.setProgressDrawable(mylayer); seekbar.setProgress(50); }
这是我将所有内容放在一起的代码,我在其中设置了搜索栏的高度:
public MySeekbar(Activity activity,absoluteLayout ParentLayout,SeekbarParameters parameters) { super(activity.getApplicationContext()); seekbar =(Seekbar)activity.getLayoutInflater().inflate(R.layout.horizontal_seek_bar,ParentLayout,false); seekbar.setMax(100); setSeekbarThumb(parameters.wIDthThumb,parameters.heightThumb,100,0); setSeekbarProgress(parameters.wIDth,parameters.height,255,69,0); int drawHeight; if(parameters.height>parameters.heightThumb) drawHeight=parameters.height; else drawHeight=parameters.heightThumb; absoluteLayout.LayoutParams params = new AsoluteLayout.LayoutParams(parameters.wIDth,drawHeight,parameters.xposition,parameters.yposition); ParentLayout.addVIEw(seekbar,params); }
我向以下栏中填充栏的XML代码:
<Seekbar xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:gravity="center" androID:layout_gravity="center" androID:max="100" androID:progress="0" androID:secondaryProgress="0" androID:maxHeight="10000dip" androID:ID="@+ID/slIDer" />
要更改搜索栏的大小,我使用ParentLayout.addVIEw(seekbar,params).
添加视图时,如果我使用了我想要的高度,那么拇指就会受到割伤.如果我使用拇指的高度,则栏会达到拇指的相同高度. AndroID将栏的大小调整为我用来添加视图的大小.
我尝试设置GradIEntDrawable的大小,即带有shape.setSize(宽度,高度)的栏,我也尝试了shape.setBounds(0,height),我尝试使用正确的大小创建另一个图像并添加到LayerDrawable mylayer.但没有任何效果.
通过XML创建时,可以使用paddingtop和paddingBottom将条形图调整到合适的大小.但我不知道如何以编程方式对GradIEntDrawable执行此 *** 作.
解决方法 好吧,太糟糕没有回应,但我能够自己回答这个问题.答案是使用InsetDrawable.您必须将条形的一个drawable放入InsetDrawable中.这是代码:
public voID setSeekbarProgress(int wIDth,int bcolor){ GradIEntDrawable shape2 = new GradIEntDrawable(OrIEntation.BottOM_top,bcolor)}); shape2.setCornerRadius(50); ClipDrawable clip = new ClipDrawable(shape2,ClipDrawable.HORIZONTAL); GradIEntDrawable shape1 = new GradIEntDrawable(OrIEntation.BottOM_top,getResources().getcolor(R.color.Dimgray)}); shape1.setCornerRadius(50);//change the corners of the rectangle InsetDrawable d1= new InsetDrawable(shape1,5,5);//the padding u want to use LayerDrawable mylayer = new LayerDrawable(new Drawable[]{d1,clip}); seekbar.setProgressDrawable(mylayer); seekbar.setProgress(50); }
我希望这可以帮助其他人解决同样的问题.
总结以上是内存溢出为你收集整理的android – 以编程方式更改搜索栏的大小,但不能使拇指大于栏全部内容,希望文章能够帮你解决android – 以编程方式更改搜索栏的大小,但不能使拇指大于栏所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)