i am developing layout.i developed drawable for this layout.but text is not adjust in this view.anyone tell me about library are anyother guidlines please provide me.thanks
Asked
Active
Viewed 2,418 times
3 Answers
2
In Android there is a method setRotation(float), which you can use it
textview.setRotation(float);
NOTE: this method was added in API 11
so if you want to support it you can use this
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);
}
EDIT: Here's my solution:
Here's my full 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>
For creating triangle, create triangle.xml
file in this directory:
your_app_name/app/src/main/res/drawable
and as content put this code:
<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>
In your Java MainActivity
class put:
TextView oldPrice = (TextView) findViewById(R.id.old_price);
oldPrice.setPaintFlags(oldPrice.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
to add to your old price text strike-through effect.
If you have a question, please free to ask. Hope it help

piotrek1543
- 19,130
- 7
- 81
- 94
-
1543 thanks.. but text is not animation my requirement.. my requirement is text is fixed.. – Muhammad Waleed Dec 29 '15 at 11:25
-
I've already added my solution, hope it help – piotrek1543 Dec 29 '15 at 13:54
-
1thanks bro..it is working.... – Muhammad Waleed Dec 30 '15 at 07:16
1
The easiest way to do is:
<TextView
android:id="@+id/rotated"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:background="#AA000F"
android:rotation="-50"
android:text="ABC"
android:textColor="#44CC44"
android:textSize="32sp" />
You can do it with the other layouts or edittexts too

asad.qazi
- 2,449
- 3
- 23
- 35
-
-
-
-
This make the text exactly tilted as you wanted. Actually you've to create a layout and then add both the text view in that layout ... and make them tilted... – asad.qazi Dec 29 '15 at 11:35
1
There is property in TextView . You can rotate by as per your requirement
Please refer below example for reference
<TextView
android:id="@+id/won_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:paddingTop="20dp"
android:rotation="-45"
android:text="@string/won"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@android:color/white"
android:textSize="34sp" />

Anjali Tripathi
- 1,477
- 9
- 28