I want create a Button in Vertically.May be we can by extending a button and re-render(rotate) the canvas to vertical we can get the custom Button. But i need it from xml.check the graphical representation.i need a button like this. 解决方案 Please, see link below, there should be solution for your problemhttp://blog.stylingandroid.com/archives/796This is tutorial about how to create vertical-textViewBut because of Button class extends TextView this tutorial should work for Buttons tooUPDATE:1) Create a style in res/values/styles.xml which we’l use later: <?xml version="1.0" encoding="utf-8"?> <resources xmlns:android="http://schemas.android.com/apk/res/android"> <style name="verticalTextStyle" parent="android:Widget.TextView"> <item name="android:padding">20dp</item> <item name="android:textSize">20sp</item> </style> </resources>2) replace the default string named hello with one named text to res/values/strings.xml: <?xml version="1.0" encoding="utf-8"?> <resources> <string name="text">Vertical Text</string> <string name="app_name">VerticalText</string> </resources>3) Create custom VerticalTextView class public class VerticalTextView extends TextView { final boolean topDown; public VerticalTextView( Context context, AttributeSet attrs ) { super( context, attrs ); final int gravity = getGravity(); if ( Gravity.isVertical( gravity ) && ( gravity & Gravity.VERTICAL_GRAVITY_MASK ) == Gravity.BOTTOM ) { setGravity( ( gravity & Gravity.HORIZONTAL_GRAVITY_MASK ) | Gravity.TOP ); topDown = false; } else { topDown = true; } } @Override protected void onMeasure( int widthMeasureSpec, int heightMeasureSpec ) { super.onMeasure( heightMeasureSpec, widthMeasureSpec ); setMeasuredDimension( getMeasuredHeight(), getMeasuredWidth() ); } @Override protected void onDraw( Canvas canvas ) { TextPaint textPaint = getPaint(); textPaint.setColor( getCurrentTextColor() ); textPaint.drawableState = getDrawableState(); canvas.save(); if ( topDown ) { canvas.translate( getWidth(), 0 ); canvas.rotate( 90 ); } else { canvas.translate( 0, getHeight() ); canvas.rotate( -90 ); } canvas.translate( getCompoundPaddingLeft(), getExtendedPaddingTop() ); getLayout().draw( canvas ); canvas.restore(); } }4) change our main layout in res/layout/main.xml to include a VerticalTextView control:<com.stylingandroid.verticaltext.VerticalTextView style="@style/verticalTextStyle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="bottom|right" android:text="@string/text" />5) ResultSource: http://blog.stylingandroid.com/archives/796 这篇关于如何从xml获取垂直按钮视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-10 19:49