가로 ProgressBar에서 세로 패딩 제거
기본적으로 ProgressBar에는 막대 자체 위와 아래에 특정 패딩이 있습니다. 막대가 어디에서 오나요? 패딩을 제거하는 방법이 있습니까?
이 문제의 해결 방법으로 다음을 사용합니다.
android:layout_marginBottom="-8dp"
android:layout_marginTop="-4dp"
내가 Juozas의 대답을 방법입니다.
내 키 ProgressBar는 4dp입니다. 내가 만든 그래서 FrameLayout높이 4dp로 설정 layout_gravity의 ProgressBar에 center. 그것은 매력처럼 작동합니다.
<FrameLayout
android:layout_width="match_parent"
android:layout_height="4dp">
<ProgressBar
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="4dp"
android:layout_gravity="center"
android:indeterminate="true"/>
</FrameLayout>
이 문제를 해결하기 위해 사용자 정의 라이브러리를 사용했습니다. 다른 솔루션의 대부분은 작동하지만 다양한 장치에서 결과가 일치하지 않습니다.
MaterialProgressBar
- Android 4.0 이상에서 일관된 모양.
- 플랫폼 간 올바른 배열.
- Framework ProgressBar의 내장 패딩을 제거 할 수 있습니다.
- 프레임 워크 가로 ProgressBar의 트랙을 숨길 수 있습니다.
- 프레임 워크 ProgressBar의 드롭 인 대체로 사용됩니다.
gradle 추가 비용으로 다음을 수행하십시오.
compile 'me.zhanghai.android.materialprogressbar:library:1.1.7'
레이아웃에 내장 패딩이없는 ProgressBar를 추가 비용으로
<me.zhanghai.android.materialprogressbar.MaterialProgressBar
android:layout_width="wrap_content"
android:layout_height="4dp"
android:indeterminate="true"
app:mpb_progressStyle="horizontal"
app:mpb_useIntrinsicPadding="false"
style="@style/Widget.MaterialProgressBar.ProgressBar.Horizontal" />
app:mpb_useIntrinsicPadding="false"트릭을 수행합니다. 자세한 내용은 GitHub 페이지를 참조하십시오 .
패딩을 잘라내는 내부에 세로로 중앙에있는 ProgressBar를 그릴 수 있습니다. ProgressBar는 부모보다 더 크게 그릴 수 있습니다.
<FrameLayout
android:id="@+id/clippedProgressBar"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="4dp"
tools:ignore="UselessParent">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="16dp"
android:layout_gravity="center_vertical">
<ProgressBar
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:indeterminate="true"/>
</FrameLayout>
</FrameLayout>
이 문제에 대한 해결책은 다음과 다양합니다. 누군가가 코드 조각이 필요한 경우에 대비하여 내가 한 일입니다.
- 8 개의 불확실한 수평 진행 막대 드로어 블을 모두 복사했습니다.
- 일부 이미지 조작기를 사용하여 드로어 블을 편집하고 불필요한 패딩을 제거했습니다.
- android 플랫폼에서 progress_indeterminate_horizontal_holo.xml이라는 드로어 블 XML을 복사했습니다.
- Widget.ProgressBar.Horizontal 스타일과 부모 스타일을 복사했습니다.
- 레이아웃에서 style 및 min_height를 수동으로 설정하십시오.
다음은 progress_indeterminate_horizontal_holo.xml입니다.
<animation-list
xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">
<item android:drawable="@drawable/progressbar_indeterminate_holo1" android:duration="50" />
<item android:drawable="@drawable/progressbar_indeterminate_holo2" android:duration="50" />
<item android:drawable="@drawable/progressbar_indeterminate_holo3" android:duration="50" />
<item android:drawable="@drawable/progressbar_indeterminate_holo4" android:duration="50" />
<item android:drawable="@drawable/progressbar_indeterminate_holo5" android:duration="50" />
<item android:drawable="@drawable/progressbar_indeterminate_holo6" android:duration="50" />
<item android:drawable="@drawable/progressbar_indeterminate_holo7" android:duration="50" />
<item android:drawable="@drawable/progressbar_indeterminate_holo8" android:duration="50" />
스타일 리소스가 로컬 스타일 파일로 복사되었습니다.
<style name="Widget">
<item name="android:textAppearance">@android:attr/textAppearance</item>
</style>
<style name="Widget.ProgressBar">
<item name="android:indeterminateOnly">true</item>
<item name="android:indeterminateBehavior">repeat</item>
<item name="android:indeterminateDuration">3500</item>
</style>
<style name="Widget.ProgressBar.Horizontal">
<item name="android:indeterminateOnly">false</item>
<item name="android:indeterminateDrawable">@drawable/progress_indeterminate_horizontal_holo</item>
</style>
마지막으로 로컬 레이아웃 파일에서 최소 높이를 4dp로 설정하십시오.
<ProgressBar
android:id="@+id/pb_loading"
style="@style/Widget.ProgressBar.Horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:indeterminate="true"
android:minHeight="4dp"
android:minWidth="48dp"
android:progressDrawable="@drawable/progress_indeterminate_horizontal_holo" />
여전히 도움이 필요한 사람은 다음을 시도하십시오.
<androidx.core.widget.ContentLoadingProgressBar
android:id="@+id/progress"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/Widget.AppCompat.ProgressBar.Horizontal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@+id/guideline" android:indeterminate="true"
android:visibility="visible" app:layout_constraintBottom_toTopOf="@+id/guideline"/>
여기서, 진행 막대의 내부 ConstraintLayout 및 constraintTop_toTopOf 및 constraintBottom_toTopOf 특성 (이 경우, 지침이다).
가로 스타일로 진행률 표시 줄을 사용하는 동안 동일한 문제가 발생했습니다.
근본 원인은 진행률 표시 줄에 대한 기본 9 패치 드로어 블 (progress_bg_holo_dark.9.png)에 패딩으로 세로 투명 픽셀이 있기 때문입니다.
나를 위해 일한 최종 솔루션 : 진행 코드, 사용자 정의 샘플 코드를 다음과 같이 사용자 정의하십시오.
custom_horizontal_progressbar_drawable.xml
<?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 android:shape="rectangle">
<solid android:color="#33ffffff" />
</shape>
</item>
<item android:id="@android:id/secondaryProgress">
<clip>
<shape android:shape="rectangle">
<solid android:color="#ff9800" />
</shape>
</clip>
</item>
<item android:id="@android:id/progress">
<clip>
<shape android:shape="rectangle">
<solid android:color="#E91E63" />
</shape>
</clip>
</item>
</layer-list>
레이아웃 스 니펫 :
<ProgressBar
android:id="@+id/song_progress_normal"
style="@style/Widget.AppCompat.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:layout_height="5dp"
android:layout_alignParentBottom="true"
android:progressDrawable="@drawable/custom_horizontal_progressbar_drawable"
android:progress="0"/>
의 세로 패딩을 제거하려면 ProgressBar다음을 수행하면됩니다.
- 높이를 고치다
ProgressBar - scaleY = "value"사용 (값 = 높이 / 4) (4는 기본 진행률 표시 줄)
예는 1 wrap_content ProgressBar, 1 8dp ProgressBar, 1 100dp를 포함합니다.ProgressBar
<ProgressBar
style="?android:attr/progressBarStyleHorizontal"
...
android:layout_height="8dp"
android:scaleY="2" />
Subin의 대답은 Android ProgressBar 릴리스에서 깨지기 쉬운 해킹 대상이 아닌 것입니다 (현재).
그러나 자원을 분해하고 수정하고 무기한으로 유지 관리하는 데 어려움을 겪지 않고 MaterialProgressBar 라이브러리 를 사용하기로 선택했습니다 .
<me.zhanghai.android.materialprogressbar.MaterialProgressBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:indeterminate="true"
android:layout_gravity="bottom"
custom:mpb_progressStyle="horizontal"
custom:mpb_showTrack="false"
custom:mpb_useIntrinsicPadding="false"
style="@style/Widget.MaterialProgressBar.ProgressBar.Horizontal.NoPadding"
/>
build.gradle에서 :
// Android horizontal ProgressBar doesn't allow removal of top/bottom padding
compile 'me.zhanghai.android.materialprogressbar:library:1.1.6'
이 프로젝트에는 프로젝트 와 내장 ProgressBar의 색다른 멋진 연습이 있습니다.
한 가지 방법은 진행률 표시 줄에 음수 여백을 추가하는 것입니다.
아래는 화면 상단에 가정 한 XML 코드의 예입니다.
<ProgressBar
android:id="@+id/progressBar"
style="@style/Widget.AppCompat.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="-7dp"
android:layout_marginBottom="-7dp"
android:indeterminate="true" />
minHeight와 maxHeigh를 사용합니다. 다른 Api 버전에 도움이됩니다.
<ProgressBar
android:id="@+id/progress_bar"
style="@style/Base.Widget.AppCompat.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxHeight="3dp"
android:minHeight="3dp" />
둘 다 어울립니다. API 23은 잘 작동합니다.
android:layout_height="wrap_content"
android:minHeight="0dp"
그러나이 경우 낮은 Api 버전은 진행률 막대 높이를 maxHeight로 개선합니다.
다음을 시도하십시오.
<ProgressBar
android:id="@+id/progress_bar"
style="@android:style/Widget.ProgressBar.Horizontal"
android:progress="25"
android:progressTint="@color/colorWhite"
android:progressBackgroundTint="@color/colorPrimaryLight"
android:layout_width="match_parent"
android:layout_height="4dp" />
... 그리고 진행률 표시 줄을 필요에 맞게 구성하면 처음에는 회색 진행률과 함께 노란색 진행률이있는 중간 크기의 막대가 표시됩니다. 또한 세로 패딩이 없습니다.
android : progressDrawable을 drawable에 정의 된 레이어 목록에 추가하면 문제가 해결되었습니다. 커스텀 드로어 블에서 프로 게스 바를 마스킹하여 작동합니다.
https://stackoverflow.com/a/4454450/1145905에 설명 된 구현 예
나는 사용 style="@style/Widget.AppCompat.ProgressBar.Horizontal"하고 있고 여백을 제거하는 것은 매우 신뢰할 수 있습니다. 그 스타일은 :
<item name="progressDrawable">@drawable/progress_horizontal_material</item>
<item name="indeterminateDrawable">@drawable/progress_indeterminate_horizontal_material</item>
<item name="minHeight">16dip</item>
<item name="maxHeight">16dip</item>
방금 최소 / 최대 높이를 무시했습니다.
<ProgressBar
style="@style/Widget.AppCompat.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:layout_height="2dp"
android:indeterminate="true"
android:minHeight="2dp"
android:maxHeight="2dp" />
<ProgressBar
android:layout_marginTop="-8dp"
android:layout_marginLeft="-8dp"
android:layout_marginRight="-8dp"
android:id="@+id/progress_bar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="4dp"
android:indeterminate="false"
android:indeterminateTint="@color/white"
android:max="100"
android:paddingStart="8dp"
android:paddingRight="0dp"
android:progressDrawable="@drawable/progress_bg" />
새 모듈을 다운로드하거나 진행률 표시 줄 주위에 FrameLayout을 배치 할 필요가 없습니다. 이것들은 모두 해킹입니다. 2 단계 만 :
당신의 whatever.xml에서
<ProgressBar
android:id="@+id/workoutSessionGlobalProgress"
android:layout_width="match_parent"
android:layout_height="YOUR_HEIGHT"
android:progressDrawable="@drawable/progress_horizontal"
android:progress="0"
<!-- High value to make ValueAnimator smoother -->
android:max="DURATION * 1000"
android:indeterminate="false"
style="@style/Widget.MaterialProgressBar.ProgressBar.Horizontal"/>
progress_horizontal.xml, 원하는대로 값을 변경하십시오.
둥근 모서리가 마음에 들지보실 수 있습니까?
코너 반경 제거
색상이 마음에 들지 보급 적입니까? 색상 등을 변경하십시오!
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background">
<shape>
<corners android:radius="5dip" />
<gradient
android:startColor="#ff9d9e9d"
android:centerColor="#ff5a5d5a"
android:centerY="0.75"
android:endColor="#ff747674"
android:angle="270"
/>
</shape>
</item>
<item android:id="@android:id/secondaryProgress">
<clip>
<shape>
<corners android:radius="5dip" />
<gradient
android:startColor="#80ffd300"
android:centerColor="#80ffb600"
android:centerY="0.75"
android:endColor="#a0ffcb00"
android:angle="270"
/>
</shape>
</clip>
</item>
<item android:id="@android:id/progress">
<clip>
<shape>
<corners android:radius="5dip" />
<gradient
android:startColor="#ffffd300"
android:centerColor="#ffffb600"
android:centerY="0.75"
android:endColor="#ffffcb00"
android:angle="270"
/>
</shape>
</clip>
</item>
</layer-list>
일반적으로 다음은 당신이 싫어하는 코드를 변경하는 단계입니다. 소스 코드를 찾고 무엇을 변경해야하는지 알아 내십시오. ProgressBar 소스 코드를 따르면 참조하는 progress_horizontal.xml이라는 파일이 있습니다. 기본적으로 모든 XML 문제를 해결하는 방법입니다.
최선의 해결책은
android:minHeight="0dp"
해결 방법이 없으며 매력처럼 작동합니다.
안드로이드의 모든 버전과 호환되며 외부 라이브러리를 필요로하지 않는 간단한 노 트릭 솔루션은 날조되어 ProgressBar두 사람과 함께 Views내부 LinearLayout. 이것이 내가 끝낸 것입니다. 매우 깔끔해 보이며이 접근 방식은 매우 유연합니다. 펑키 한 방식으로 애니메이션을 적용하고 텍스트를 추가 할 수 있습니다.
형세:
<LinearLayout
android:id="@+id/inventory_progress_layout"
android:layout_width="match_parent"
android:layout_height="4dp"
android:orientation="horizontal">
<TextView
android:id="@+id/inventory_progress_value"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<TextView
android:id="@+id/inventory_progress_remaining"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
암호:
public void setProgressValue(float percentage) {
TextView progressValue = (TextView) findViewById(R.id.inventory_progress_value);
TextView progressRemaining = (TextView) findViewById(R.id.inventory_progress_remaining);
LinearLayout.LayoutParams paramsValue = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
LinearLayout.LayoutParams paramsRemaining = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
paramsValue.weight = (100 - percentage);
paramsRemaining.weight = percentage;
progressValue.setLayoutParams(paramsValue);
progressRemaining.setLayoutParams(paramsRemaining);
}
결과 (일부 고도가 추가됨) :
참고 URL : https://stackoverflow.com/questions/14171471/remove-vertical-padding-from-horizontal-progressbar
'IT' 카테고리의 다른 글
| RandomForestClassifier의 feature_importances는 어떻게 결정? (0) | 2020.07.29 |
|---|---|
| Wireshark 로컬 호스트 트래픽 배포 (0) | 2020.07.29 |
| C ++ 11의 코드 풀링 (0) | 2020.07.29 |
| 파일 린트를 사용하여 하나의 특정 라인을 무시할 수 있습니까? (0) | 2020.07.29 |
| 사전을 파일로 저장하는 방법? (0) | 2020.07.28 |


