答案 0 :(得分:2)
我已经在我的一个应用程序上完成了这样的工作。 我在here ...
上共享了代码您必须将TextView替换为我的代码中使用的ImageView。
如果你卡在某个地方,请告诉我......
快乐编码:)
答案 1 :(得分:0)
使用SlopeTextView代替普通文本视图。试试这个:
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Typeface;
import android.util.AttributeSet;
import android.view.Gravity;
import android.widget.TextView;
public class SlopeTextView extends TextView{
final boolean topDown;
public SlopeTextView(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 boolean setFrame(int l, int t, int r, int b){
return super.setFrame(l, t, l+(b-t), t+(r-l));
}
@Override
public void draw(Canvas canvas){
Paint paint = new Paint();
paint.setTypeface(Typeface.DEFAULT);
paint.setStyle(Paint.Style.FILL);
canvas.rotate(-45,getHeight(),0);
super.onDraw(canvas);
}
}
实施:
<com.example.myviews.SlopeTextView
android:id="@+id/slopeTextView"
android:layout_width="60dp"
android:layout_height="70dp"
android:layout_marginTop="5dp"
android:gravity="left|top"
android:text="Featured"
android:textColor="@color/white"
android:textSize="@dimen/text_medium" />