目前正在构建基于浏览器的SVG应用程序.在这个应用程序中,用户可以设置和定位各种形状,包括矩形.
当我将一个stroke-width
SVG rect
元素应用于某个SVG 元素时1px
,rect
不同浏览器会以不同的方式将笔划应用于偏移和插入.这被证明是麻烦的,特别是当我尝试计算矩形的外部宽度和视觉位置并将其放置在其他元素旁边时.
例如:
到目前为止,我唯一的解决方案是自己绘制实际边界(可能使用path
工具)并将边框定位在描边元素后面.但是这个解决方案是一个令人不快的解决方案,如果可能的话,我宁愿不走这条路.
所以我的问题是,你能控制如何stroke-width
在元素上绘制SVG 吗?
我想在 SVG中显示一些文本rect
.可能吗?
我试过了
<svg xmlns="http://www.w3.org/2000/svg">
<g>
<rect x="0" y="0" width="100" height="100" fill="red">
<text x="0" y="10" font-family="Verdana" font-size="55" fill="blue"> Hello </text>
</rect>
</g>
</svg>
Run Code Online (Sandbox Code Playgroud)
但它不起作用.
Android SDK中Rect和RectF有什么区别?
我已经在网上搜索了几天,试图找到关于如何在Swift中以程序方式绘制矩形或线条的最简单的代码示例.我已经看过如何通过覆盖DrawRect命令来完成它.我相信你可以创建一个CGContext然后绘制成一个图像,但我很想看到一些简单的代码示例.或者这是一种可怕的方法?谢谢.
class MenuController: UIViewController
{
override func viewDidLoad()
{
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.view.backgroundColor = UIColor.blackColor()
var logoFrame = CGRectMake(0,0,118,40)
var imageView = UIImageView(frame: logoFrame)
imageView.image = UIImage(named:"Logo")
self.view.addSubview(imageView)
//need to draw a rectangle here
}
}
Run Code Online (Sandbox Code Playgroud) 我认为这是一个非常简单的请求,但我似乎无法在搜索中找到确凿的答案.如何确定窗口中特定视觉元素相对于其他父元素的边界?
我尝试过使用,LayoutInformation.GetLayoutSlot
但这似乎只返回Rect
0,0并没有反映元素的实际位置.
我正在尝试做的是使用窗口的"屏幕截图",RenderTargetBitmap
然后将其裁剪为特定元素,但我无法获得元素的界限,知道要将位图裁剪为什么!
这个问题不同于测试一个rect是否在另一个rect中.
已知信息是两个长度的边长.
如何计算一个矩形是否可以放入另一个矩形?
我需要滚动到HorizontalScrollView的childView(TextView)的中心.我通过使用下面的代码获得了中心孩子,现在我想将箭头调整到该子视图的确切中心.
在这里,我所做的是我拿了一个HorizontalScrollView,里面有一个LineaerLayout,在LinearLayout里面我有TextViews.
这是我的XML:
<com.sample.test.ScrollViewCustom
android:id="@+id/mHorizontalScrollViewMain"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="@id/relativeOne"
android:background="@drawable/mergethree2"
android:scrollbars="none" >
<LinearLayout
android:id="@+id/llayoutfirst"
android:layout_width="wrap_content"
android:layout_height="55dip"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dip"
android:background="@drawable/blackline" />
<TextView
android:id="@+id/mtxtHome"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="5dip"
android:layout_marginLeft="5dip"
android:layout_marginRight="5dip"
android:layout_marginTop="8dip"
android:text="home"
android:textColor="@android:color/white"
android:textSize="15sp"
android:typeface="serif" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dip"
android:background="@drawable/blackline" />
<TextView
android:id="@+id/mtxtSchools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="5dip"
android:layout_marginLeft="5dip"
android:layout_marginRight="5dip"
android:layout_marginTop="8dip"
android:text="schools"
android:textColor="@android:color/white"
android:textSize="15sp"
android:typeface="serif" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dip"
android:background="@drawable/blackline" />
<TextView
android:id="@+id/mtxtCalendar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="5dip"
android:layout_marginLeft="5dip"
android:layout_marginRight="5dip"
android:layout_marginTop="8dip"
android:text="calendar"
android:textColor="@android:color/white"
android:textSize="15sp"
android:typeface="serif" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content" …
Run Code Online (Sandbox Code Playgroud) 我想模仿视图中的"放大".较大的视图将作为子视图添加到较小视图的超视图中,较大的视图应该看起来好像从较小的视图放大.给定较小视图的矩形fromRect
和放大的视图的最终帧,finalRect
适当的变换是什么?
我想方法签名就像下面这样,view
作为superview.我写这篇文章来帮助自己,但还是想不出来.
-(CGAffineTransform) translatedAndScaledTransformUsingViewRect:(CGRect)viewRect fromRect:(CGRect)fromRect inView:(UIView*) view
{
//calculate the scaling based on the final frame of viewToBeStretched (viewRect) vs the "fromRect"
CGFloat scaleX = ?, scaleY = ?;
CGAffineTransform scaleTransform = CGAffineTransformMakeScale(scaleX, scaleY);
//use translation instead of modifying the view's center, since frame changes with transforms are no good
CGFloat translationX = ?, translationY =?;
CGAffineTransform translationTransform = CGAffineTransformMakeTranslation(translationX, translationY);
CGAffineTransform final = CGAffineTransformConcat(scaleTransform, translationTransform);
return final;
}
Run Code Online (Sandbox Code Playgroud)