Android:使用Button [英] Android: Working with Button

查看:65
本文介绍了Android:使用Button的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我正在创建一个简单的游戏,Tic Tac Toe ...



我从界面开始。有人可以建议如何使按钮的完美方块。我设置的宽度取决于屏幕尺寸。

Hi I am creating a simple game, Tic Tac Toe...

I'm starting with the interface. Can someone suggest on how can I make the button's perfect square. I have set the width depends on what is the screen size.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"

    tools:context="com.hansoctantan.tictactoe.Activity" >

    <LinearLayout

        android:layout_width="match_parent"

        android:layout_height="match_parent"

        android:layout_alignParentLeft="true"

        android:layout_alignParentTop="true"

        android:orientation="vertical" >

        <TextView

            android:id="@+id/textView1"

            android:layout_width="match_parent"

            android:layout_height="wrap_content"

            android:gravity="center"

            android:text="Large Text"

            android:textAppearance="?android:attr/textAppearanceLarge" />

        <LinearLayout

            android:layout_width="match_parent"

            android:layout_height="wrap_content" >

            <TextView

                android:id="@+id/textView2"

                android:layout_width="0dp"

                android:layout_height="wrap_content"

                android:layout_weight="1"

                android:text="Your Turn"

                android:textAppearance="?android:attr/textAppearanceMedium" />

            <TextView

                android:id="@+id/textView3"

                android:layout_width="0dp"

                android:layout_height="wrap_content"

                android:layout_weight="1"

                android:text="Player1: 0"

                android:textAppearance="?android:attr/textAppearanceMedium" />

            <TextView

                android:id="@+id/textView4"

                android:layout_width="0dp"

                android:layout_height="wrap_content"

                android:layout_weight="1"

                android:text="Player2: 0"

                android:textAppearance="?android:attr/textAppearanceMedium" />
        </LinearLayout>

        <LinearLayout

            android:layout_width="match_parent"

            android:layout_height="wrap_content" >

            <Button

                android:id="@+id/button1"

                android:layout_width="0dp"

                android:layout_height="wrap_content"

                android:layout_weight="1" />

            <Button

                android:id="@+id/button2"

                android:layout_width="0dp"

                android:layout_height="wrap_content"

                android:layout_weight="1" />

            <Button

                android:id="@+id/button3"

                android:layout_width="0dp"

                android:layout_height="wrap_content"

                android:layout_weight="1" />

        </LinearLayout>
    </LinearLayout>

</RelativeLayout>





I know java but started andriod yesterday.



Thanks



Additional

if there’s a way/code in class that can do this, its also appreciated.



Thanks Ag ain...



I know java but started andriod yesterday.

Thanks

Additional
if there's a way/code in class that can do this, its also appreciated.

Thanks Again...

推荐答案

Have you ever try with to create the background shape for any buttons?



Check with below:



below is the separated image from your image of button.



![enter image description here][1]



Now, put that in your ImageButton as src like below:



Have you ever try with to create the background shape for any buttons?

Check with below:

below is the separated image from your image of button.

![enter image description here][1]

Now, put that in your ImageButton as src like below:

android:src="@drawable/twitter"<pre>





Now, just create shape of the ImageButton to have black shader background.





Now, just create shape of the ImageButton to have black shader background.

android:background="@drawable/button_shape"





and the button_shape is the xml file in drawable resource:





and the button_shape is the xml file in drawable resource:

    <shape>
        xmlns:android="http://schemas.android.com/apk/res/android">
        <stroke>
            android:width="1dp" 
            android:color="#505050"/>
        <corners>
          	android:radius="7dp" />
    
        <padding>
            android:left="1dp"
            android:right="1dp"
            android:top="1dp"
            android:bottom="1dp"/>
        
        <solid android:color="#505050" xmlns:android="#unknown" />
           
    </padding></corners></stroke></shape>


Just try to implement with this. Might above code needs to change some color value as per your requirement.

Let me know if its not work.


  Sandeep


这篇关于Android:使用Button的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆