2014-02-15 3 views
0

엄지 클리핑과 관련된 많은 stackoverflow 질문은 내 질문과 관련이없는 왼쪽 및 오른쪽 클리핑과 관련이 있습니다.동적으로 크기가 조정 된 SeekBar의 Thumb이 위아래로 잘린 채 어떻게 맨 위 (Z 순서)에 그리는가?

엄지 손가락은 이미지입니다. SeekBar 슬라이드가 오른쪽으로 확대 될 때 이미지 크기가 onProgressChanged로 재설정됩니다.

문제는 SeekBar보기의 상단을 터치 할만큼 이미지의 키가 커지면 상단이 맨 위에 닿으면서 이미지의 크기가 계속 조정됩니다. 시각적으로 엄지 이미지가 페이지 아래로 이동하는 것처럼 보입니다.

원하는 것은 (1) 이미지가 오른쪽으로 밀려서 이미지가 막대 중앙에 오도록하는 것입니다. (2) SeekBar 뷰 내부에서 클리핑 된 것이 아닌 모든 것의 TOP에 그려 질 엄지 이미지.

SeekBar 뷰와 함께 bringToFront()를 시도했지만 아무 것도 변경하지 않았습니다.

번호 :

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 레이아웃 의 maxHeight 파라미터 (안드로이드 :의 maxHeight = "1000dp")는 수직 검색 막대를 중심으로하여 이미지를 유지할 수있는 대안이다

<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. 

답변

0

(1) 대답 없음. 엄지 손가락에 이미지 드로어 블을 사용하고 동적으로 크기를 조절하면 크기가 커질 때 SeekBar 뷰의 맨 위에 정렬되므로 다른 방법을 모를 수 있습니다. 스크린 공간이 충분한 경우 상단을 채우면 이미지가 커질 수있는 공간이 늘어납니다.

(2)의 답은 요소를 서로 겹치게 배치하고, RelativeLayout을 사용하여 LinearLayouts에서 각 "행의 행"을 보유하는 대신 모든 요소를 ​​포함하는 것입니다. 클리핑은 별도의 선형 레이아웃에있는 일련의 항목에서 발생합니다.

그래서 모든 물건과 함께 RelativeLayout의이 모든 것이 같은 위치를 레이아웃 태그를 사용 : 코드에서

    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" 

(엄지 손가락에 대한 이미지가이 경우 SeekBar를) 요소 앞에 가져 할 수 있습니다 startTrackingTouch에서 bringToFront()와 함께

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