0

我想在其上显示一个带有文字的线,但它不应该是垂直或水平的,而应该是45°角。我正在使用一个包含TextView和View的RelativeLayout(对于该行)。在RelativeLayout.LayoutParams的帮助下,我尝试定义RelativeLayout的x/y位置。水平显示器已经可以工作,但是如何将其更改为45°角?Android:我如何在LinearLayout中定义45°视角(RelativeLayout)

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); 

整个屏幕执行仅用于“风景”×0-800,Y 0-440 眼下

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

计划是要显示的字符串和线一起在45°角。线的长度取决于字符串宽度。

希望任何人都可以帮我这个困境,

萨斯基亚

回答

0

,因为x和y位置的问题是,RelativeLayout的变得非常巨大。 所以我删除了布局branch_item_layout并在branch_item上添加了参数和动画内容。

见你,

萨斯基亚

+0

不要回答每一个时间..只是编辑您的第一个答案。 – SERPRO 2012-03-07 10:04:37

相关问题