Giter Club home page Giter Club logo

slantedtextview's Introduction

Android Arsenal

SlantedTextView

Android slanted TextView . 中文版

Preview

预览

Gradle

compile 'com.haozhang.libary:android-slanted-textview:1.2'

XML Layout

<com.haozhang.lib.SlantedTextView
    android:layout_width="80dp"
    android:layout_height="80dp"
    android:gravity="center"
    app:slantedBackgroundColor="@color/secondary_text"
    app:slantedLength="40dp"
    app:slantedMode="left"
    app:slantedText="IOS"
    app:slantedTextColor="@color/primary"
    app:slantedTextSize="16sp"
    />

Java

    SlantedTextView stv = (SlantedTextView) findViewById(R.id.test);

    stv.setText("PHP")
            .setTextColor(Color.WHITE)
            .setSlantedBackgroundColor(Color.BLACK)
            .setTextSize(18)
            .setSlantedLength(50)
            .setMode(SlantedTextView.MODE_LEFT);

Attributes

注意

SlantedMode

SlantedMode

License

Copyright 2016 Hand HaoZhang

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

slantedtextview's People

Contributors

bryant1410 avatar hezaijin avatar hikarinosenritsu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

slantedtextview's Issues

font

can not find option for change font family!

Extend from TextView for better usability

You should extend from TextView so that we can use the view with TextSwitchers and other stuff that works only with TextViews. I think #1 has a great description on how this may work.

Just a few lines to accomplish your results and more

extend from TextView and override the draw method:

Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
public void draw(Canvas canvas) {
    RectF rect = new RectF(ShrinkX, ShrinkY, getMeasuredWidth() - ShrinkX, getMeasuredHeight() - ShrinkY);

    if (OffsetX != 0 || OffsetY != 0) {
            canvas.translate(OffsetX, OffsetY);
        }

        if (Rotation != 0) {
            canvas.rotate(Rotation, rect.centerX(), rect.centerY());
        }

    if (RoundRadius > 0) {
        Path path = new Path();
        path.addRoundRect(rect, RoundRadius, RoundRadius, Path.Direction.CCW);
        canvas.clipPath(path);
    }

    paint.setColor(BackColor);
    canvas.drawRect(rect, paint);

    super.draw(canvas);
}

And of course you need to define some variables:

public int      RoundRadius = 0;
public int    BackColor   = 0;
public float    Rotation        = 0f;
public int    OffsetX           = 0;
public int    OffsetY           = 0;
public int      ShrinkX         = 0;
public int      ShrinkY         = 0;

关于背景色渐变效果

您好打扰了,请问一下我想把背景色改成渐变的颜色,要怎么做?
mPaint?.shader = LinearGradient(
0f, 0f, w.toFloat(), h.toFloat(),
intArrayOf(mSlantedBackgroundGradient[0], mSlantedBackgroundGradient[1])
, null
, Shader.TileMode.MIRROR
)
我使用了 shader方法,但是没有起作用,
不知道您最近有没有时间帮忙指导一下,非常感谢

当背景设置成黄色,字体设置成其他颜色时看不到字,不知道是不是方式不对

@HeZaiJin
当背景设置成黄色,字体设置成其他颜色时看不到字,不知道是不是方式不对

<com.shtoone.shtw.ui.SlantedTextView android:id="@+id/stv_handle_item_recyclerview_yaliji_fragment_viewpager_fragment" android:layout_width="50dp" android:layout_height="50dp" android:layout_gravity="bottom|right" android:gravity="center" app:slantedBackgroundColor="#ffff00" app:slantedLength="25dp" app:slantedMode="right_bottom_triangle" app:slantedText="未处置" app:slantedTextColor="#000000" app:slantedTextSize="12sp" />

试过好多种颜色都没用,就是看到黄色背景,看不到字
请问这是Bug吗?

use custom font

how can i use custom fonts on this widget? for example http://fontawesome.io/cheatsheet/

my code dont work for example:

if (!isInEditMode()) {
    if (mTextFontFamily != null || !mTextFontFamily.isEmpty()) {
        mTextTypeFace = Utils.findFont(mContext, mTextFontFamily, mDefaultTextFont);
    } else {
        mTextTypeFace = Utils.findFont(mContext, mDefaultTextFont, null);
    }
}
mTextPaint.setTypeface(mTextTypeFace);
mSlantedText="&#xf032;";

能否将这个两个属性去掉

<application
    android:allowBackup="true"
    android:supportsRtl="true" >
</application>

添加了这两个属性后,如果我将这两个属性设置为false,将导致无法编译。

Rendering problem

When I use it into my app in layout preview I got this error:
Failed to find the style corresponding to the id -1

布局中如果放在CardView的上层,不显示。

布局代码如下时,不显示SlantedTextView.

<android.support.v7.widget.CardView
    android:layout_width="match_parent"
    android:layout_height="200dp"
    app:cardBackgroundColor="@color/white"
    app:cardCornerRadius="5dp"
    app:cardElevation="2dp"
    app:cardMaxElevation="2dp">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="8dp"
        android:orientation="vertical">

        <ImageView
            android:layout_width="80dp"
            android:layout_height="80dp"
            android:scaleType="centerCrop"
            android:src="@drawable/image_default" />
    </LinearLayout>
</android.support.v7.widget.CardView>

<com.haozhang.lib.SlantedTextView
    android:id="@+id/item_recommend_slanted_tv"
    android:layout_width="100dp"
    android:layout_height="100dp"
    android:layout_alignParentRight="true"
    android:gravity="center"
    app:slantedBackgroundColor="#607D88"
    app:slantedLength="40dp"
    app:slantedMode="right"
    app:slantedText="IOS"
    app:slantedTextColor="@color/black"
    app:slantedTextSize="16sp" />

java.lang.IllegalStateException: SlantedTextView's width must equal to height, w: 96, h: 155

Hi, thanks for great library, I have a question : I can't use latest your library, always say width and height not equals, but its equal in layout:

 <com.haozhang.lib.SlantedTextView
    android:id="@+id/prStatusTV"
    android:layout_width="48dp"
    android:layout_height="48dp"
    android:layout_alignParentTop="true"
    android:layout_alignParentStart="true"
    android:layout_alignParentLeft="true"
    android:layout_above="@+id/productNameTV"
    android:gravity="center"
    android:text="@string/i_sold_this_pr_txt"
    android:textColor="@color/colorWhite"
    android:fontFamily="sans-serif-condensed"
    app:slantedBackgroundColor="@color/colorAccent"
    app:slantedMode="left_triangle"
    app:slantedText="IOS"
    app:slantedTextColor="@color/colorWhite"
    app:slantedLength="28dp"
    app:slantedTextSize="10sp"
    />

where problem?

我想知道我这么设置为什么不显示字呢?谢谢!

<com.haozhang.lib.SlantedTextView
android:id="@+id/slantedTextView"
android:layout_width="50dp"
android:layout_height="50dp"
app:slantedText="android"
app:slantedLength="30dp"
app:slantedMode="left_triangle"
app:slantedTextSize="12sp"
app:slantedTextColor="@color/colorAccent"
app:slantedBackgroundColor="#000000"
android:layout_alignTop="@+id/imageView"
android:layout_alignEnd="@+id/slantedTextView2" />

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.