0

我想在上面显示一条带有文本的行,但它不应该是垂直或水平的,它应该是 45° 角。我正在使用包含 TextView 和 View 的 RelativeLayout (用于行)。在 RelativeLayout.LayoutParams 的帮助下,我尝试定义 RelativeLayout 的 x/y 位置。水平显示已经可以了,但是如何将其更改为 45° 角?

    RelativeLayout branch_layout = (RelativeLayout) this
            .findViewById(R.id.createrelativelayout);

    LinearLayout branch_item = new LinearLayout(this);
    branch_item.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT));
    branch_item.setOrientation(1);
    TextView tv = new TextView(this);
    tv.setLayoutParams(new RelativeLayout.LayoutParams(pos, pos));
    tv.setId(id);
    tv.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT));
    tv.setPadding(20, 0, 20, 0);
    tv.setText(branch_name);
    tv.setOnClickListener(this);

    Rect bounds = new Rect();
    Paint textPaint = tv.getPaint();
    textPaint.getTextBounds(branch_name, 0, branch_name.length(), bounds);
    View underline = new View(this);
    underline.setLayoutParams(new LayoutParams(bounds.width() + 40, 1));
    underline.setBackgroundColor(Color.parseColor("#000000"));

    branch_item_layout = new RelativeLayout(this);
    branch_item_layout.setLayoutParams(new LayoutParams(
            LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
            LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    Display display = getWindowManager().getDefaultDisplay();
    //x
    params.leftMargin = display.getWidth()/2;
    //y
    params.topMargin = ((display.getHeight()/2)-(((LinearLayout) this
            .findViewById(R.id.createlinearlayout3)).getWidth()/2)-48);

    //end x
    params.bottomMargin = params.leftMargin + bounds.width();
    //end y
    params.rightMargin = (int) (params.leftMargin - (bounds.width()*Math.sin(45)));

    branch_item.addView(tv);
    branch_item.addView(underline);

    branch_item_layout.addView(branch_item, params);
    branch_layout.addView(branch_item_layout);

全屏实现只针对“横向” x 0-800, y 0-440 现在

first x = 400
first y = 114
end x   = 434
end y   = 371

计划以 45° 角一起显示字符串和线条。线的长度以字符串宽度为方向。

希望任何人都可以帮助我解决这个难题,

萨斯基亚

4

1 回答 1

0

由于 x 和 y 位置的问题是相对布局变得非常大。所以我删除了布局branch_item_layout并在branch_item上添加了参数和动画的东西。

再见,

萨斯基亚

于 2012-03-07T10:02:53.060 回答