Tag: 布局

在VideoView中放置video

所以我扩展了VideoView的onMeasure以扩大video,以适应全屏视图。 这里是如何: public void setVideoAspect(int w,int h){ wVideo=w; hVideo=h; onMeasure(w, h); } @Override protected void onMeasure (int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); if(wVideo!=0 && hVideo!=0) setMeasuredDimension(wVideo,hVideo); } 我用屏幕的显示度量(宽度,高度)调用setVideoAspect()。 问题是,这种方法拉伸video适合在屏幕内。 我希望能够保持宽高比。 (我有4:3的video和3:2的屏幕尺寸。)我使用下面的代码给保留的比例测量视图: int height = (int) (metrics.widthPixels*3/(float)4); int width= metrics.widthPixels; mVideoView.setVideoAspect(width,height); 所以这样做的工作,但有一个问题:它给了我一个4:3的video与屏幕的宽度,并正确地缩放高度,但它不居中的video。 (它只是裁剪video的底部而不是顶部和底部)。我有一个包含VideoView的相对布局,以VideoView的重心为中心。

UICollectionView – 水平滚动,水平布局?

我有一个UIScrollView,列出了一个图标的网格。 如果你想象iOS跳板的布局,你会非常接近正确的。 它有一个水平的页面滚动(就像跳板)。 但是,看起来布局不太正确。 看起来好像是从上到下布置项目。 因此,由于要显示的项目数量,我的最后一列只有2行。 我宁愿让最后一页的最后一行有两个项目,就像你在Springboard中看到的一样。 这怎么可以用UICollectionView和它的相关类来完成? 我必须编写一个自定义的UICollectionViewFlowLayout吗?

android包含标签 – 无效的布局引用

我有一个问题,包括通过包含在android layout xml文件中的标签不同的布局。 在指定布局引用(@layout / …)时,我得到了Eclipse ADT中的InflateException,并出现以下错误: InflateException:您必须指定一个有效的布局引用。 布局ID @ layout / func_edit_simple_calculator_toolbox无效。 引用应该是有效的,因为我从我的其他布局的列表中select它,并没有input它。我使用的Android SDK的V2.1 这些是布局文件 func_edit_simple_calculator_toolbox.xml <?xml version="1.0" encoding="utf-8"?> <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="wrap_content" android:layout_width="wrap_content"> <TableRow android:id="@+id/TableRow01" android:layout_width="wrap_content"android:layout_height="wrap_content"> <Button android:id="@+id/Button01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="1"></Button> <Button android:id="@+id/Button02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="2"></Button> <Button android:id="@+id/Button03" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="3"></Button> <Button android:id="@+id/Button04" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="+"></Button> </TableRow> <TableRow android:id="@+id/TableRow02" android:layout_width="wrap_content" android:layout_height="wrap_content"> <Button android:id="@+id/Button05" android:layout_width="wrap_content" […]

Haskelllogging语法

Haskell的logging语法被许多人认为是对其他优雅语言的一种讽刺,因为它的丑陋语法和命名空间污染。 另一方面,通常比基于位置的select更有用。 而不是像这样的声明: data Foo = Foo { fooID :: Int, fooName :: String } deriving (Show) 在我看来,沿着这些路线的东西会更有吸引力: data Foo = Foo id :: Int name :: String deriving (Show) 我肯定有一个很好的理由,我错过了,但为什么类似C语言的logging语法通过一个更干净的布局为基础的方法? 其次,有没有什么可以解决命名空间问题,所以我们可以在未来的Haskell版本中编写id foo而不是fooID foo ? (除了目前可用的longwinded基于类的解决方法之外)。

为什么在我的UIViewController的顶部20px的差距?

问题 考虑以下控制器层次结构: UINavigationController UIViewController UITableViewController UIViewController的存在影响布局。 没有它, UITableViewController将占用UINavigationController的整个界限: 但是,如果我在UINavigationController和UITableViewController之间添加了一个vanilla UIViewController ,那么在UIViewController的顶端和UITableViewController的顶端之间会出现一个20px的间隔: 即使我把代码缩减到最简单的事情,我仍然观察到这种行为。 考虑这个应用程序委托代码: public override bool FinishedLaunching(UIApplication app, NSDictionary options) { window = new UIWindow(UIScreen.MainScreen.Bounds); var tableView = new UITableViewController(); var intermediateView = new UIViewController(); var navigation = new UINavigationController(intermediateView); navigation.View.BackgroundColor = UIColor.Red; intermediateView.View.BackgroundColor = UIColor.Green; tableView.View.BackgroundColor = UIColor.Blue; intermediateView.AddChildViewController(tableView); intermediateView.View.AddSubview(tableView.View); tableView.DidMoveToParentViewController(intermediateView); window.RootViewController = navigation; […]

Android:比android更好:ellipsize =“end”添加“…”截断长string?

这个属性使得 “短而长的词” 至 “短”和“ 。 但是我想要平静下来。 喜欢 “短而长…” 现在我截断Java代码中的string。 但是,那是基于字符的数量而不是链接的实际长度。 所以,结果不是很好。 String title; if(model.getOrganization().length() > 19) { title = model.getText().substring(0, 15).trim() + "…"; } else { title = model.getText(); } ((TextView) findViewById(R.id.TextViewTitle)).setText(title); 更新 刚注意到,这个属性实际上在几个例子中增加了“…”。 但是并不是全部都是这样: 12345678901234567890变成“12345678901234 …” 然而, “1234567890 1234567890”变成“1234567890”而不是“1234567890 123 …” 更新2 现在它真的变得时髦了! 我只是设置singleLine = true,并删除maxLine(错误出现与没有设置ellipsize属性)… 这是从摩托罗拉里程碑与Android 2.1更新1的截图。相同的HTC Desire上发生相同的Android版本 更新3 现在我使用android:ellipsize =“marquee”。 这似乎是唯一适当的工作环境。 聚焦时也只是在移动。 […]

2个button并排 – android布局

我怎么能把2个button并排放置,这样它们就占据了所有的宽度,它们之间有一点空间。 我认为一个水平线性布局,与2个子线性布局设置为匹配父母和重量1,每个包含button..有没有一个更简单的方法? 这可以通过相对布局来完成吗? 谢谢!

xCode 6 beta 7:故事板在右侧和左侧增加了额外的空间

当我添加子视图到根视图控制器的视图,并与自动布局设置的领导空间,尾随空间,topSpace和底部空间为零,左右两侧出现一些额外的空间(所以如果我打印子视图的框架,它的原点将是16,比32应该是)。 所以实际上,我们得到的领先和尾随空格不是零… 正如你所看到的图片领先空间 – 零,但origin.x = 16 早些时候,我没有努力与自动布局,所以我的问题是:这是一个新的xCode或function的错误? PS所有框架和限制已更新。

什么是'UIView-Encapsulated-Layout-Width'约束?

我一直在“无法同时满足约束”的例外(Xcode 5,iOS 7,设备和模拟器),列表中的约束之一是这样的: "<NSLayoutConstraint:0x165b23d0 'UIView-Encapsulated-Layout-Width' H:[StoryPlayerCell:0x165affc0(0)]>" 我没有自己设置这个约束。 这也不是一个NSAutoresizingMaskLayoutConstraint 。 但是它从哪里来? 我怎样才能摆脱它? 我不知道。 而且在Apple的文档中我找不到有关'UIView-Encapsulated-Layout-Width'的信息。 即使是Googlesearch也没有任何回报。 有什么build议么? PS:我在UICollectionView中使用UICollectionView的自定义子类中的这个单元格。 也许'Encapsulated-Layout'部分与此有关?

NullPointerException不指向我的代码中的任何行

我正在玩游戏,玩家可以在屏幕上拖放东西。 我有一个私人的方法,允许我模拟玩家可以移动的任何物品的拖放事件。 对于拖拽,我实际上将视图放在它们所在的位置,然后创build一个新的ImageView,并从触摸的视图中将drawable设置为drawingCache,然后将这个新创build的ImageView沿着它们的手指在屏幕上移动。 当你松开你的手指(放下视图),我打电话给myLayout.remove(movingImg); 把它从屏幕上取下来 我有一个问题,如果我开始一个模拟拖动事件,然后手动拿起其中一个项目,我得到一个空指针myLayout.remove()调用,这里是来自日志的跟踪: 04-06 10:37:43.610: ERROR/AndroidRuntime(23203): java.lang.NullPointerException 04-06 10:37:43.610: ERROR/AndroidRuntime(23203): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2122) 04-06 10:37:43.610: ERROR/AndroidRuntime(23203): at android.view.ViewGroup.drawChild(ViewGroup.java:2506) 04-06 10:37:43.610: ERROR/AndroidRuntime(23203): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2123) 04-06 10:37:43.610: ERROR/AndroidRuntime(23203): at android.view.ViewGroup.drawChild(ViewGroup.java:2506) 04-06 10:37:43.610: ERROR/AndroidRuntime(23203): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2123) 04-06 10:37:43.610: ERROR/AndroidRuntime(23203): at android.view.ViewGroup.drawChild(ViewGroup.java:2506) 04-06 10:37:43.610: ERROR/AndroidRuntime(23203): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2123) 04-06 10:37:43.610: ERROR/AndroidRuntime(23203): at android.view.ViewGroup.drawChild(ViewGroup.java:2506) 04-06 10:37:43.610: ERROR/AndroidRuntime(23203): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2123) […]