1

다음은 여러 가지 안드로이드 4.x 장치에서 실행되지만 안드로이드 2.3 (장치 및 장치)에서는 예상대로 작동하는 목록보기 항목의 매우 레이아웃입니다. 에뮬레이터).안드로이드 2.x 실행시 레이아웃의 전체 가로 가로 진행 바

예상 : 진행률 표시 줄은이 항목의 배경을 가로 및 세로 모두 포함해야합니다. 안드로이드 2.3에 Expected

: ProgressBar의 진행이> 0을 설정, 항상 전체로 표시되고 높이가 전체 항목, 바로 상단을 포함하지 않습니다. Not working

레이아웃 XML : 나는 ProgressBar의 최대 값, 프로그램 및 XML에 포함 등 여러 가지를 시도했습니다

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/shadowBackgroundHolder" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:background="@drawable/selected_shadow_top_and_bottom" > 

    <ProgressBar 
     android:id="@+id/progressBar" 
     style="?android:attr/progressBarStyleHorizontal" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_margin="0dp" 
     android:padding="0dp" 
     android:progressDrawable="@drawable/progress_timer" /> 

    <TextView 
     android:id="@+id/currentTime" 
     android:layout_width="wrap_content" 
     android:layout_height="50dp" /> 

    <TextView 
     android:id="@+id/timer_name" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" /> 

</FrameLayout> 

. 프레임 레이아웃 대신 동일한 레이아웃을 사용하여 상대 레이아웃 (암시 적 z- 정렬)을 시도했습니다. 0dp의 여백과 여백은 중요하지 않습니다.

흥미로운 점은 wrap_content를 사용하여 너비를 줄이면 더 짧은 진행 표시 줄이 표시되지만 진행률을 0보다 큰 값으로 설정하면 항상 채워집니다. TextView 중 하나의 높이가 50dp 인 것은이 예에 불과합니다. 스크린 샷에 문제를 명확하게 표시하려면 문제가되지 않습니다.

다른 사람이이를 확인하거나 더 나은 아이디어가있는 이유는 무엇입니까? 더 나은 방법은 해결책이나 해결책입니까?

전체 높이를 덮지 않고 다른 레이아웃을 사용하여 2.x 장치에서 작동하도록 진행률 표시 줄을 얻을 수 있습니다. 현재 버전의 앱이지만 다음 버전에서는 전체 항목 높이를 대신 활용합니다. 2.x 장치 용 솔루션을 선택하는 것은 최적의 솔루션이 아닙니다.

업데이트 : 나는 그것이 전체 높이 다루 얻을 수 있지만, 여전히 진행 전체 항상 대신 RelativeLayout의 사용의 예. ProgressBar 구성 요소에 다음과 같은 추가 속성을 사용하여 : example problem 2

+0

이 원인 일 수 있습니다.이 항목을 제거하십시오. –

+0

감사합니다. 이미이 문제를 포함하여 질문을 업데이트했습니다. –

+0

그럴 경우 @ Mr.Me이 대답을 대답으로 바꾸어 주시면 받아 들일 것입니다! 넥서스 원을 2.3으로 다시 반사시키고 HTC Desire에서도 테스트합니다. 다른 모든 테스트 장치는 현재 4.x를 실행하고 있으므로 어쨌든 (필자가 에뮬레이터를 사용하여 테스트 한 이유) 일부를 다운 그레이드하는 것이 좋습니다. –

답변

0

위의 "업데이트"섹션의 버전을 사용하고 내가 속임수뿐만 아니라 안드로이드 2.X에 "작품"진행 상황을 업데이트 한 후이를 추가하는 경우 :

if (!Application.hasHoneycomb()) { 
    LayoutParams layoutParams = progressBar.getLayoutParams(); 
    layoutParams.width = ((View) progressBar.getParent()).getWidth() * progressBar.getProgress()/progressBar.getMax(); 
    progressBar.setLayoutParams(layoutParams); 
} 

것은 그래서 진행 입니다 여전히은 항상 가득 차 있습니다. 전체 진행 막대의 크기 (너비) 만 변경하면됩니다. 그것은 아마도 매우 효율적이지는 않지만 ... 해결 방법이지만 실제 해결책은 아닙니다.

0

나는 비슷한 문제가 있었다 : 진행> 0 경우 안드로이드 2.3 장치에

android:layout_alignBottom="@id/content" 
android:layout_alignLeft="@id/content" 
android:layout_alignTop="@id/content" 

이 가득 참으로 높이지만 진전이 항상 여전히 가득 차있다. 이 진행 표시 줄이 지금 나를 위해 노력하고 있습니다 :

<LinearLayout 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:orientation="vertical" 
tools:context=".MoDa" > 

<TextView 
    android:id="@+id/title" 
    style="?textTitle" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/app_name" /> 

<ProgressBar 
    android:id="@+id/progressbar" 
    style="?android:attr/progressBarStyleHorizontal" 
    android:layout_width="fill_parent" 
    android:layout_height="8dp" 
    android:max="100" 
    android:visibility="gone" /> 

<FrameLayout 
    android:id="@+id/frame" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_gravity="top|center_horizontal" 
    android:orientation="horizontal" > 

(자세한 레이아웃은 다음) 진행 바는 텍스트 뷰 아래의 전체 폭

희망이 내 앞에서 미안 해요,

+0

불행히도 그게 나를 도울 수는 없지만, LinearLayout에서 위에 추가하여 전체 높이가 아닌 전체 너비에서도 괜찮습니다. 나를 위해 문제는 전체 레이아웃 (일종의 배경으로), 즉 FrameLayout 또는 RelativeLayout을 포함하도록하는 것입니다. –

1

확인하는 데 도움이 의견, 내 코드 기반을 검토 한 결과 버그 자체가 ProgressBar 구현과 관련이 있음을 알게되었습니다.

그래서 텍스트 뷰를 확장하지만 의 ProgressBar 겉 모양을 가진 뷰를 생성에 모험. 언제든지 복사하여 개선 할 수 있습니다.

import android.widget.TextView; 

import android.content.Context; 
import android.graphics.Canvas; 
import android.graphics.Color; 
import android.graphics.Paint; 
import android.graphics.Paint.Style; 
import android.graphics.Rect; 
import android.util.AttributeSet; 
import android.util.Log; 

public class ProgressTextView extends TextView { 
private float mProgress = 0; 
private int progressColor; 
private int backgroundColor; 
private Paint strokePaint; 
private static final String tag = ProgressTextView.class.getSimpleName(); 

public ProgressTextView(Context context) { 
    super(context); 
} 
public ProgressTextView(Context context, AttributeSet attrs) { 
    super(context, attrs); 
} 
public ProgressTextView(Context context, AttributeSet attrs, int defStyle) { 
    super(context, attrs, defStyle); 

} 

@Override 
public void draw(Canvas canvas) { 
     canvas.save(); 
     setBackgroundColor(progressColor); 
     canvas.clipRect(new Rect(0, 0, (int)(getWidth() * mProgress), getHeight())); 
     super.draw(canvas); 
     canvas.restore(); 
     setBackgroundColor(backgroundColor); 
     canvas.clipRect(new Rect((int)(getWidth() * mProgress), 0, getWidth(), getHeight())); 
     super.draw(canvas); 
     Rect rect = canvas.getClipBounds(); 
     if(strokePaint != null) { 
      canvas.drawRect(rect, strokePaint); 
     } 
     canvas.restore(); 


} 

public void setProgressColor(int color){ 
    progressColor = color; 
} 
public void setProgress(int progress) { 
    if (progress > 100) { 
     return; 
    } 
    if (mProgress == 0) { 
     backgroundColor =Color.GRAY; 
    } 
    strokePaint = new Paint(); 
    strokePaint.setColor(progressColor); 
    strokePaint.setStrokeWidth(5); 
    strokePaint.setStyle(Style.STROKE); 
    mProgress = progress/ (float) 100; 
    Log.i(tag, "update progress: " + mProgress); 

    invalidate(); 
} 
} 
+0

감사합니다. 다른 도움이되지 않으면 그 길을 따라갈 수도 있습니다. 하지만 2 차 진행, 스타일링 등을 사용하여보다 완벽한 구현이 필요합니다. –