动态搜索栏的调整大小的拇指被夹住上方和下方,如何在顶部(Z顺序)画?拇指、夹住、顺序、大小

由网友(逢旧人)分享简介:许多与拇指裁剪计算器的问题是关注的​​剪辑的左,右,这是不相关的我的问题。拇指是一个图像。图像规模复位,以扩大规模为搜索栏右侧滑动onProgressChanged。 的问题是,当图像获取足够高触摸搜索栏视图的顶部,图像继续同时保持顶部接触顶部按比例的。因此,在视觉上,它看起来像拇指图像向下移动的页面。​​希望的为(1...

许多与拇指裁剪计算器的问题是关注的​​剪辑的左,右,这是不相关的我的问题。

拇指是一个图像。图像规模复位,以扩大规模为搜索栏右侧滑动onProgressChanged。

的问题是,当图像获取足够高触摸搜索栏视图的顶部,图像继续同时保持顶部接触顶部按比例的。因此,在视觉上,它看起来像拇指图像向下移动的页面。​​

希望的

为(1)的图像,以保持该栏上居中作为图像滑动右。 (2)拇指图像上的一切,而不是搜索栏视图内修剪的顶部绘制。

我曾尝试bringToFront()与搜索栏的看法,但它不会改变任何东西。

codeS:

  SeekBar.OnSeekBarChangeListener SBCL =新SeekBar.OnSeekBarChangeListener(){                @覆盖                公共无效onProgressChanged(搜索栏搜索栏,INT I,布尔B){                    资源解析度= getResources();                    INT渣油=(整数)seekbar.getTag();                  // Log.i(R丘壑在听众:,+渣油);                    可绘制拇指= res.getDrawable(渣油);                    双H =​​(双)thumb.getIntrinsicHeight();                    双W =(双)thumb.getIntrinsicWidth();                    双迪=(双)我;                    H = H * 0.2; //规模对于那些方式的大图标                    W = W * 0.2;                    Log.i(求2,H+ H +W:+ W);                    W = W *(DI / 200 + 0.5);                    H = H *(DI / 200 + 0.5);                    Log.i(求3,H+ H +W:+ W +的i+ I);                    如果(W&所述; 1){W = 1;}如果(H&所述; 1){H = 1;}                    位图bmpOrg =((BitmapDrawable)拇指).getBitmap();                    位图bmpScaled = Bitmap.createScaledBitmap(bmpOrg,(INT)W,(INT)H,真正的);                    可绘制newThumb =新BitmapDrawable(RES,bmpScaled);                    newThumb.setBounds(0,0,newThumb.getIntrinsicWidth(),newThumb.getIntrinsicHeight());                    seekbar.setThumb(newThumb);                } 

的.xml布局对了maxHeight参数(安卓了maxHeight =1000dp)是保持垂直居中上的SeekBar的图像解决方法

 <的RelativeLayout的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android    的xmlns:工具=htt​​p://schemas.android.com/tool​​s    机器人:layout_width =match_parent    机器人:layout_height =match_parent    机器人:paddingLeft =@扪/ activity_horizo​​ntal_margin    机器人:paddingRight =@扪/ activity_horizo​​ntal_margin    机器人:paddingTop =@扪/ activity_vertical_margin    机器人:paddingBottom会=@扪/ activity_vertical_margin    工具:上下文=$ sic.emo.apptt.GetProtectorData PlaceholderFragment>    < sic.eco.appt.VerticalScrollView        机器人:layout_width =match_parent        机器人:layout_height =match_parent        机器人:fillViewport =真        机器人:方向=垂直        机器人:layout_weight =1>            <的LinearLayout                机器人:方向=垂直                机器人:layout_width =match_parent                机器人:layout_height =100dp>              <的TextView                    机器人:layout_width =WRAP_CONTENT                    机器人:layout_height =WRAP_CONTENT                    机器人:textAppearance =机器人:ATTR / textAppearanceLarge                    机器人:文字=@字符串/ LabelSA                机器人:layout_gravity =中心                    机器人:ID =@ + ID / textLabelSA/>              <搜索栏                机器人:layout_width =match_parent                机器人:layout_height =80dp                机器人:ID =@ + ID / seekBarPS                机器人:拇指=@绘制/狗                安卓了maxHeight =1000dp                机器人:hapticFeedbackEnabled =真                机器人:layout_gravity =CENTER_HORIZONTAL/>            < / LinearLayout中>            等等,等等 

解决方案

(1)没有答案。使用图像绘制拇指和动态扩展它,当它到达大它对齐其顶部的搜索栏视图,以便不知道如何使不同的顶部。填充顶部将给予更多的空间为图像增加,如果有足够的屏幕空间。

的答案(2)是具有元件放置在彼此的顶部,使用RelativeLayout的以包含所有的元素,而不是在LinearLayouts保持每个的东西行。裁剪来自东西在不同的线性布局是行。

所以有所有的东西,一个RelativeLayout的,并使用布局标签来定位一切都像:

 的android:layout_alignTop =@ + ID / textLabel1                    机器人:SRC =@绘制/ ic_action_about                    机器人:layout_alignParentRight =假                    机器人:layout_alignParentLeft =真                    机器人:layout_alignParentEnd =假                    机器人:paddingLeft =0dp                    机器人:layout_marginLeft = -  10dp                    机器人:layout_marginTop = -  18dp 
逆向而行 诺基亚Z Launcher体验

在code中的元素(与拇指图片这种情况下,搜索栏)可以被带到前面加上bringToFront()在startTrackingTouch

  @覆盖 公共无效onStartTrackingTouch(搜索栏搜索栏){                    seekBar.bringToFront();                } 

Many stackoverflow questions related to thumb clipping are concerned with clipping to the left and right, which is not related to my question.

Thumb is an image. The image scale is reset onProgressChanged in order to scale up as the SeekBar slides right.

The issue is that when the image gets tall enough to touch the top of the SeekBar view, the image continues to scale while keeping the top touching the top. So visually it looks like the thumb image is moving down the page.

Desired is for (1) the image to stay centered on the bar as the image is slid right. (2) the thumb image to be drawn ON TOP of everything rather than clipped inside the SeekBar view.

I have tried bringToFront() with the SeekBar view but it doesn't change anything.

codes:

SeekBar.OnSeekBarChangeListener sbcl = new SeekBar.OnSeekBarChangeListener() {
                @Override
                public void onProgressChanged(SeekBar seekbar, int i, boolean b) {
                    Resources res = getResources();
                    int resID = (Integer)seekbar.getTag();
                  //  Log.i("R vals in Listener :"," "+resID);
                    Drawable thumb = res.getDrawable(resID);
                    double h = (double)thumb.getIntrinsicHeight();
                    double w = (double)thumb.getIntrinsicWidth();
                    double di = (double)i;
                    h = h * 0.2;  //scale for icons that are way to big
                    w = w * 0.2;
                    Log.i("seek 2"," h: "+h+" w: "+ w);
                    w = w * (di/200 + 0.5);
                    h = h * (di/200 + 0.5);
                    Log.i("seek 3"," h: "+h+" w: "+ w +" i: "+ i);
                    if (w<1) {w = 1;} if (h<1) {h = 1;}

                    Bitmap bmpOrg = ((BitmapDrawable)thumb).getBitmap();
                    Bitmap bmpScaled = Bitmap.createScaledBitmap(bmpOrg, (int)w, (int)h, true);
                    Drawable newThumb = new BitmapDrawable(res, bmpScaled);
                    newThumb.setBounds(0, 0, newThumb.getIntrinsicWidth(), newThumb.getIntrinsicHeight());
                    seekbar.setThumb(newThumb);
                }

.xml layout the maxHeight parameter (android:maxHeight="1000dp") is a workaround to keep the image vertically centered on the SeekBar

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context="sic.emo.apptt.GetProtectorData$PlaceholderFragment">

    <sic.eco.appt.VerticalScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true"
        android:orientation="vertical"
        android:layout_weight="1">


            <LinearLayout
                android:orientation="vertical"
                android:layout_width="match_parent"
                android:layout_height="100dp">
              <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textAppearance="?android:attr/textAppearanceLarge"
                    android:text="@string/LabelSA"
                android:layout_gravity="center"
                    android:id="@+id/textLabelSA" />
              <SeekBar
                android:layout_width="match_parent"
                android:layout_height="80dp"
                android:id="@+id/seekBarPS"
                android:thumb="@drawable/dog"
                android:maxHeight="1000dp"
                android:hapticFeedbackEnabled="true"
                android:layout_gravity="center_horizontal" />

            </LinearLayout>

            etc. etc.

解决方案

(1) no answer. using image drawable for the thumb, and scaling it dynamically, when it gets big it aligns its top with the top of the SeekBar view so not sure how to make that different. Padding the top will give more space for the image to grow, if there's enough screen space.

The answer to (2) is to have elements lay on top of each other, use RelativeLayout to contain all the elements rather than holding each "row of stuff" in LinearLayouts. The clipping comes from the row of stuff being in separate Linear Layouts.

So have a RelativeLayout with all the stuff and use the Layout tags to position everything like:

                    android:layout_alignTop="@+id/textLabel1"
                    android:src="@drawable/ic_action_about"
                    android:layout_alignParentRight="false"
                    android:layout_alignParentLeft="true"
                    android:layout_alignParentEnd="false"
                    android:paddingLeft="0dp"
                    android:layout_marginLeft="-10dp"
                    android:layout_marginTop="-18dp"

In the code the element (in this case SeekBar with images for thumbs) can be brought to the front with bringToFront() in the startTrackingTouch

 @Override
 public void onStartTrackingTouch(SeekBar seekBar) {
                    seekBar.bringToFront();
                }

阅读全文

相关推荐

最新文章