在Android中有一个方法设置旋转(浮动) http://developer.android.com/reference/android/view/View.html#setRotation%28float%29,你可以使用它
textview.setRotation(float);
注意:该方法被添加到API 11
所以如果你想支持它你可以使用这个
if (Build.VERSION.SDK_INT < 11) {
RotateAnimation animation = new RotateAnimation(oldAngel, newAngel);
animation.setDuration(100);
animation.setFillAfter(true);
watermarkText.startAnimation(animation);
} else {
watermarkText.setRotation(progress);
}
编辑:这是我的解决方案:
这是我的完整activity_main.xml
:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tool="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimary">
<RelativeLayout
android:id="@+id/item"
android:layout_width="200dp"
android:layout_height="200dp"
android:background="#FFFFFFFF"
>
<TextView
android:layout_width="match_parent"
android:layout_height="40dp"
android:textColor="#FFFFFFFF"
android:text="HP EliteBook 1212x"
android:textAlignment="gravity"
android:gravity="center"
android:background="@color/colorPrimaryDark"
/>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="40dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_margin="0dp"
android:src="@drawable/laptop"/>
<ImageView
android:layout_width="175dp"
android:layout_height="175dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_margin="0dp"
android:padding="0dp"
android:src="@drawable/triangle"/>
<LinearLayout
android:id="@+id/prices"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:orientation="vertical"
android:padding="7dp"
android:rotation="-45.0"
android:textAlignment="center">
<TextView
android:id="@+id/old_price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="200$"
android:textColor="#FFFFFFFF"
/>
<TextView
android:id="@+id/new_price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/old_price"
android:layout_gravity="center"
android:text="400$"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#FFFFFFFF"/>
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
要创建三角形,请创建triangle.xml
该目录下的文件:
your_app_name/app/src/main/res/drawable
并作为内容放置此代码:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<rotate
android:fromDegrees="-45"
android:toDegrees="0"
android:pivotX="150%"
android:pivotY="20%" >
<shape
android:shape="rectangle" >
<solid android:color="#ff0000" />
</shape>
</rotate>
</item>
</layer-list>
在你的Java中MainActivity
类放:
TextView oldPrice = (TextView) findViewById(R.id.old_price);
oldPrice.setPaintFlags(oldPrice.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
添加到您的旧价格文本删除线影响。
如果您有疑问,请随时提问。
希望有帮助