小编Imr*_*ran的帖子

Android - XML布局与程序化

我正在尝试使用相对布局和扩展视图的自定义类,以及几个按钮.这是我最终希望它看起来像:

http://imgur.com/B5MtdJ7

(原谅我张贴链接而不是图片,显然我还不够酷)

目前这是硬编码的dp高度(见下面的XML),这有两个问题:

  • 它只在我的Nexus 7屏幕上看起来可以接受,而没有其他设备
  • 两个自定义视图的onDraw方法仍然提供一个高度和宽度与完全匹配设备分辨率的画布

如果我尝试将layout_height设置为wrap_content,则每个自定义视图都会尝试占用整个屏幕,这与子弹点2一致,但显然不是我想要的.

我想实现的是有两个自定义视图,看起来完全一样显示在画面中相对布局,而是将自身扩展到它的坐在屏幕的尺寸和自定义视图画布实际上知道屏幕有多大的一部分它坐在上面.我该怎么做呢?

编辑:这是"vs programmatic"的原因是我认为覆盖测量不会是一个糟糕的呼喊,但我不知道它将如何与XML交互.我宁愿在一个地方也有布局定义.

我的XML如下:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".TrajectoryView" >

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="0.5" >

    <com.sportsim.virtualcricket.view.SideProfileView
        android:id="@+id/side_profile_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    </com.sportsim.virtualcricket.view.SideProfileView>
</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="0.5" >

    <com.sportsim.virtualcricket.view.BirdsEyeView
        android:id="@+id/birds_eye_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="0.25"
    android:orientation="horizontal" >

    <Button
        android:id="@+id/button1"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="0.5"
        android:text="Button" />

    <Button
        android:id="@+id/button2"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="0.5"
        android:text="Button" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

android android-layout

5
推荐指数
1
解决办法
728
查看次数

Rails - 在一项任务中进行Rake测试和rubocop

我正在尝试设置我的rails项目,以便贡献者所需的所有验证都在一个命令中,目前我们一直在运行:

rake test
Run Code Online (Sandbox Code Playgroud)

但是现在我们还想使用rubocop进行静态分析:

rubocop -R -a
Run Code Online (Sandbox Code Playgroud)

我希望这可以在一个简单的rake任务中执行.很高兴覆盖'rake test'来运行rubocop然后是rails项目的标准rake测试内容,因为没有人必须记住更改命令.但是如果我必须创建一个单独的rake任务,那也可能没问题.

我已经在底部看到了rubocop rake集成,但我不确定如何将"rake test"捆绑到一个任务中...有什么想法吗?

ruby rake static-analysis ruby-on-rails rubocop

4
推荐指数
1
解决办法
2815
查看次数

在类型上指定多个约束(Scala)

我正在尝试做这样的事情:

abstract class DbFinder[T <: PublicKey with Null]
Run Code Online (Sandbox Code Playgroud)

但是当我尝试将类型为T的对象返回为null时,它无法编译.以前我曾经:

abstract class DbFinder[T >: Null]
Run Code Online (Sandbox Code Playgroud)

很高兴让我回归null.

我假设我对第一行代码感到困惑.我想坚持认为T扩展了PublicKey,但T也可以为空.我该怎么做呢?

问候

types scala

2
推荐指数
1
解决办法
279
查看次数