如何为按钮内使用的可绘制图像添加笔触/边框

时间:2017-07-14 01:38:32

标签: android android-studio

我有一个按钮,里面有图像和文字 我使用 shape.xml 给css按钮

enter image description here

如何为此按钮内的图像提供css(笔划/边框)

enter image description here

图片

中以 drawableTop 的形式给出

代码:

// NOTE: This is a very simple example. The player bounces a bit on landing,
// which is essentially "landing lag" before you can jump again. In other words,
// the less the player bounces when contact the ground, the faster the player
// can jump again. There are ways to make this bouncing effect minimal / 0, but would
// require more work to implement, and I don't have any brilliantly simple ideas at the moment.
class GameScene : SKScene {

  var player = SKSpriteNode(color: .blue, size: CGSize(width: 50, height: 50))
  var initialY = CGFloat(0)

  var flag_wantsToJump = false

  override func didMove(to view: SKView) {
    self.physicsBody = SKPhysicsBody(edgeLoopFrom: self.frame)

    let pb = SKPhysicsBody(rectangleOf: player.size)
    pb.restitution = 0
    player.physicsBody = pb
    addChild(player)
  }

  override func mouseDown(with event: NSEvent) {
    // Tells game that we want to jump next frame:
    flag_wantsToJump = true
  }

  override func update(_ currentTime: TimeInterval) {
    // Give us new, initial frame data to compare against whatever our position.y will be
    // later in the frame:
    let curY = player.position.y
    initialY = curY
  }

  override func didSimulatePhysics() {

    // Determine whether or not we want to jump next frame:
    guard flag_wantsToJump else { return }

    // Determine whether or not we are allowed to jump:
    let curY = player.position.y
    print(curY, initialY)

    if curY == initialY {
      // Even though we are calling .applyImpulse this frame, it won't be processed
      // until next frame--because we are calling this from inside `didSimulatePhysics`!
      player.physicsBody!.applyImpulse(CGVector(dx: 0, dy: 75))
    }
  }

  override func didFinishUpdate() {
    // Clear our flags for new mouse / touch input for next frame:
    flag_wantsToJump = false
  }
}

Shape.xml

<Button
            android:layout_margin="8dp"
            android:onClick="CollegeNews"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:drawableTop="@drawable/doctor"
            android:drawablePadding="30dp"
            android:drawableBackground="#95a5a6"
            android:padding="15dp"
            android:gravity="center"
            android:text="Doctor"
            android:background="@drawable/shape"
            />

由于

0 个答案:

没有答案