【问题标题】:How can i change text rotation in Luck Wheel (Android)我如何在幸运轮(Android)中更改文本旋转
【发布时间】:2018-01-18 13:11:15
【问题描述】:

这里是GitHub代码链接https://github.com/thanhniencung/LuckyWheel 我尝试使用这段代码更改画布的旋转

 private void drawText(Canvas canvas, float tmpAngle, float sweepAngle, String mStr) {
    Path path = new Path();
    path.addArc(mRange,tmpAngle,sweepAngle);

    float textWidth = mTextPaint.measureText(mStr);
    int hOffset = (int) (mRadius * Math.PI / mLuckyItemList.size()/2-textWidth/2);

    int vOffset = mRadius/2/4;

    canvas.drawTextOnPath(mStr, path, hOffset, vOffset, mTextPaint);
}

我想改变文字的方向,如下图所示

【问题讨论】:

  • 而你被困在......?
  • 方向是固定的,我需要改变方向,你可以检查drawText方法,它写了一些字符串
  • @ArslanDurrani 我也在使用这个库。有没有可能获得点击切片?

标签: android github orientation android-canvas android-custom-view


【解决方案1】:

在最新版本的LuckyWheel中,当初始化LuckyItems数据时,你可以设置luckyItem.secondaryText的值而不是luckyItem.topText,你就会得到想要的文本方向。

像这样:

        List<LuckyItem> data = new ArrayList<>();
        for (int i = 0; i < sectorsTitles.length; i++) {
            LuckyItem luckyItem = new LuckyItem();
            // luckyItem.topText = sectorsTitles[i]; // Don't use this
            luckyItem.secondaryText = sectorsTitles[i]; // Use this instead
            luckyItem.color = Color.parseColor(ROULETTE_COLORS[i]);
            data.add(luckyItem);
        }
        luckyWheelView.setData(data);

【讨论】:

    【解决方案2】:

    在 XML 代码中,您可以使用更改旋转

    android:rotation="120"  (Then any angle you want positive or negative)
    

    但是,您可能需要在此图像位于底部时旋转它,然后在它位于顶部时再次旋转它。因此,您可以随时以编程方式旋转它。

    TextView textView = findViewById(R.id.textView);
    ImageView imageView = findViewById(R.id.imageView);
    
    textView.setRotation(120);
    imageView.setRotation(120);
    

    然后,如果您想稍后将其恢复到最初的位置。您只需添加负号。

    textView.setRotation(-120);
    imageView.setRotation(-120);
    

    当然,角度由你决定。

    【讨论】:

    • 这是自定义视图,没那么简单
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-22
    • 1970-01-01
    • 1970-01-01
    • 2017-03-16
    • 2020-03-19
    相关资源
    最近更新 更多