有誰知道如何使視圖顛倒,我有一個水平ProgressBar,我希望它從右到左而不是從左到右從右到左ProgressBar?
回答
使正常進度欄視圖的子類和實現onDraw方法旋轉繪製它之前的畫布:
@Override
protected void onDraw(Canvas canvas) {
canvas.save();
canvas.rotate(180,<CenterX>,<CenterY>);
super.onDraw(canvas);
canvas.restore();
}
這應該有所斬斷。
public class inverseSeekBar extends ProgressBar {
public inverseSeekBar(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// TODO Auto-generated constructor stub
}
public inverseSeekBar(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}
public inverseSeekBar(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
@Override
protected synchronized void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
canvas.save();
//now we change the matrix
//We need to rotate around the center of our text
//Otherwise it rotates around the origin, and that's bad.
float py = this.getHeight()/2.0f;
float px = this.getWidth()/2.0f;
canvas.rotate(180, px, py);
//draw the text with the matrix applied.
super.onDraw(canvas);
//restore the old matrix.
canvas.restore();
}}
<com.hlidskialf.android.widget.inverseSeekBar
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="200dip"
android:layout_height="wrap_content"
android:max="100"
android:progress="50"
android:secondaryProgress="75"
/>
mypackage的:com.test.testProgressBar
太棒了!這工作完美,謝謝! – Tom 2012-04-10 22:42:39
你不需要旋轉整個View
。
在my_progress_drawable.xml
只需使用a single xml attribute:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@android:id/background"
android:drawable="@drawable/my_background"/>
<item android:id="@android:id/progress">
<clip
android:drawable="@drawable/my_right_to_left_progress"
android:gravity="right" /> <!-- Clip the image from the RIGHT -->
</item>
</layer-list>
The documentation告訴我們,gravity="right"
做到這一點:
把對象在其容器的右邊緣,而不是改變它的大小。當clipOrientation是「水平」時,裁剪髮生在drawable的左側。
請勿覆蓋onDraw()
。此實現在不同版本的Android中更穩定。
不幸的是,無法以編程方式設置ClipDrawable
的引力而不調用其constructor。
對於使用
它更容易。你可以簡單地調用下面的方法,然後它被旋轉並按照你想要的方式工作。
progressBar.setRotation(180);
一個例子:
感謝應該是最好的答案至今 – 2013-12-31 21:41:45
代替 – 2014-04-21 07:22:04
崩潰我的應用程序... – Hamidreza 2014-09-24 08:36:22
因爲我是懶惰的我只是這兩行添加到seekbar
XML:
android:layoutDirection="rtl"
android:mirrorForRtl="true"
任何缺點這樣做呢?
可以翻轉使用的scaleX或屬性的scaleY
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleX="-1"/>
這應該是最好的答案 – 2017-05-25 07:35:45
<ProgressBar
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="100"
android:layout_margin="8dp"
android:layoutDirection="rtl"
android:progress="80" />
- 1. 大熊貓:從左到右和從右到左交替排列()從左到右
- 2. 從右到左jframe
- 3. IOS:UIViewAnimationTransitionCurlUp從右到左
- 4. 從右到左UILabels
- 5. 從右到左UINavigationController
- 6. 從左到右語言寫成從右到左html
- 7. 如何從左到右和從右到左遍歷數組?
- 8. Android:從左到右從左到右滑動
- 9. 如何從左/右移動到下一個ViewController從左到右
- 10. 從左到右從左到右堆疊框用CSS/JS
- 11. UITableView區分從左到右和從右到左滑動
- 12. 堆疊酒吧從右到左而不是從左到右
- 13. CSS轉換是從左到右,而不是從右到左
- 14. 從左到右telerik combobox從右到左mvc應用程序
- 15. Python從右到左和從左到右打印得很好
- 16. 應用程序interace佈局方向從左到右從右到左的語言返回從左到右
- 17. UIViewAnimationTransitionCurlUp從橫向(左和右)方向從右到左
- 18. 在45天左右(從左至右)從PHP/Ajax切換到Java
- 19. LinearLayout從右到左填充
- 20. 從右到左凍結列
- 21. Uiscrollview默認從左到右?
- 22. SWT RowLayout從右到左?
- 23. 在QToolBox中從左到右
- 24. Magento 2.0.2從右到左
- 25. pyplot,從左到右繪圖
- 26. Haskell函數從左到右
- 27. 數學從左到右
- 28. 顯示從左到右
- 29. 文字:從右到左(CSS)
- 30. Bootstrap 3 Collapse(從右到左)
什麼語言XML格式的看法?什麼平臺?什麼API? – EboMike 2010-10-07 00:13:00
爲什麼你需要一個RTL進度條?我看到的所有進度條都是從左到右。 – 2010-10-07 00:19:40
我們只能用僞代碼回答僞代碼問題......否則請至少指定EboMike的註釋要求的內容。 – BoltClock 2010-10-07 00:28:22