如何使自定义TextView的android系统? [英] How to make custom textview in android?

查看:227
本文介绍了如何使自定义TextView的android系统?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这里输入的形象描述

此layout.but文字

我正在开发layout.i发展绘制未在此view.anyone调整说说库中电气特性的guidlines请提供me.thanks


解决方案

在Android的是有方法的 setRotation(浮点),您可以使用它

  textview.setRotation(浮动);


  

注:加入这种方法的 API 11


所以如果你想支持它,你可以用这个

 如果(Build.VERSION.SDK_INT< 11){    RotateAnimation动画=新RotateAnimation(oldAngel,newAngel);
    animation.setDuration(100);
    animation.setFillAfter(真);
    watermarkText.startAnimation(动画);
}其他{    watermarkText.setRotation(进度);
}

编辑:这里是我的解决方案:

下面是我完全 activity_main.xml中

 <的RelativeLayout的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
                的xmlns:工具=htt​​p://schemas.android.com/tool​​s
                机器人:layout_width =match_parent
                机器人:layout_height =match_parent
                机器人:背景=@色/ colorPrimary>    < RelativeLayout的
        机器人:ID =@ + ID /项
        机器人:layout_width =200dp
        机器人:layout_height =200dp
        机器人:背景=#FFFFFFFF
        >        <的TextView
            机器人:layout_width =match_parent
            机器人:layout_height =40dp
            机器人:文字颜色=#FFFFFFFF
            机器人:文字=惠普EliteBook 1212x
            机器人:textAlignment =万有引力
            机器人:比重=中心
            机器人:背景=@彩色/ colorPrimaryDark            />        < ImageView的
            机器人:layout_width =match_parent
            机器人:layout_height =match_parent
            机器人:填充=40dp
            机器人:layout_alignParentBottom =真
            机器人:layout_alignParentRight =真
            机器人:layout_margin =0dp
            机器人:SRC =@绘制/笔记本电脑/>        < ImageView的
            机器人:layout_width =175dp
            机器人:layout_height =175dp
            机器人:layout_alignParentBottom =真
            机器人:layout_alignParentRight =真
            机器人:layout_margin =0dp
            机器人:填充=0dp
            机器人:SRC =@绘制/三角/>        <的LinearLayout
            机器人:ID =@ + ID /价格
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:layout_alignParentBottom =真
            机器人:layout_alignParentRight =真
            机器人:方向=垂直
            机器人:填充=7DP
            机器人:旋转= - 45.0
            机器人:textAlignment =中心>            <的TextView
                机器人:ID =@ + ID / OLD_PRICE
                机器人:layout_width =WRAP_CONTENT
                机器人:layout_height =WRAP_CONTENT
                机器人:layout_gravity =中心
                机器人:文字=200 $
                机器人:文字颜色=#FFFFFFFF
                />            <的TextView
                机器人:ID =@ + ID / NEW_PRICE
                机器人:layout_width =WRAP_CONTENT
                机器人:layout_height =WRAP_CONTENT
                机器人:layout_below =@ + ID / OLD_PRICE
                机器人:layout_gravity =中心
                机器人:文字=400 $
                机器人:textAppearance =机器人:ATTR / textAppearanceLarge
                机器人:文字颜色=#FFFFFFFF/>
        < / LinearLayout中>
    < / RelativeLayout的>< / RelativeLayout的>

有关创建三角形,创建 triangle.xml 文件在此目录中:

  your_app_name /应用/ src目录/主/ RES /绘

和作为内容把这个code:

 <层列表的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>
    <项目>
        <旋转
            机器人:fromDegrees = - 45
            机器人:toDegrees =0
            机器人:pivotX =150%
            机器人:pivotY =20%>
            <形状
                机器人:形状=矩形>
                [固体机器人:颜色=#FF0000/>
            < /形状>
        < /旋转>
    < /项目>
< /层列表>

在你的Java MainActivity 类地说:

  TextView的oldPrice =(的TextView)findViewById(R.id.old_price);
    oldPrice.setPaintFlags(oldPrice.getPaintFlags()| Paint.STRIKE_THRU_TEXT_FLAG);

添加到您的旧价格文本的删除线的效果。

如果您有任何问题,请请提出来。
希望这有助于

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

解决方案

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

这篇关于如何使自定义TextView的android系统?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆