0

線形レイアウトを使用してiPhone用のJeepsingアプリケーションと同じ方法でAndroidでボタンを作成しようとしていますが、成功しません。私が得る最大は同じサイズの3つの別々のボタンです。次のスクリーンショットのように、2つのボタンの角が丸い場合は、背景のない3つのボタンが必要です。

ここに画像の説明を入力してください

これが私の最後の試みです:

<LinearLayout android:id="@+id/LinearLayout02" android:layout_height="wrap_content" android:layout_width="match_parent">
    <Button android:id="@+id/Button04" android:text="Button" android:layout_width="0dp" android:layout_weight="1" android:layout_height="wrap_content"></Button>
    <Button android:id="@+id/Button05" android:text="Button" android:layout_width="0dp" android:layout_weight="1" android:layout_height="wrap_content"></Button>
    <Button android:id="@+id/Button06" android:text="Button" android:layout_width="0dp" android:layout_weight="1" android:layout_height="wrap_content"></Button>
</LinearLayout>

GridLayoutも試しましたが、成功しませんでした。

4

2 に答える 2

0

プレス/リリースされたエフェクトの両方で、コーナー半径のあるシェイプを作成するだけです。

<solid android:color="#77000000" />

<corners android:radius="10dip" />

<gradient
    android:angle="-90"
    android:endColor="#44FF0000"
    android:startColor="#CCFF0000" />

<padding
    android:bottom="10dip"
    android:left="10dip"
    android:right="10dip"
    android:top="10dip" />

<stroke
    android:width="1dip"
    android:color="#000000" >
</stroke>

形状の詳細については、こちらを参照してください

押された/離された効果の形状を作成した後、次の例のようにボタンセレクターのXMLファイルを作成します

<selector
    xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:state_pressed="true"
        android:drawable="@drawable/prs_arrival_fb_btn" /> <!-- pressed -->
    <item
        android:state_focused="true"
        android:drawable="@drawable/prs_arrival_fb_btn" /> <!-- focused -->
    <item
        android:drawable="@drawable/arrival_fb_content_btn" /> <!-- default -->
</selector>

次に、このセレクターを背景としてボタンに設定します。次の例のように。

<Button android:text="Play" android:id="@+id/playBtn"
            android:background="@drawable/button_selector"
            android:textColor="#ffffff" />
于 2013-02-27T04:25:01.930 に答える
0

これが私がそれを達成した方法です:

up_left_button_selector.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/up_left_button_shape_pressed"
      android:state_pressed="true" />
    <item android:drawable="@drawable/up_left_button_shape_pressed"
      android:state_selected="true" />
    <item android:drawable="@drawable/up_left_button_shape_released" />
</selector>

up_left_button_shape_pressed.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
    android:startColor="#ff0000ff"
    android:endColor="#ff0000ff"
    android:angle="45"/>
<padding android:left="0dp"
    android:top="0dp"
    android:right="0dp"
    android:bottom="0dp" />
<corners android:radius="8dp" 
  android:bottomRightRadius="0dp" android:bottomLeftRadius="0dp" 
  android:topLeftRadius="8dp" android:topRightRadius="0dp"/>
<stroke android:width="2dp" android:color="#ff444444"/>
</shape>

up_center_button_shape_released.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
    android:startColor="#00000000"
    android:endColor="#00000000"
    android:angle="45"/>
<padding android:left="0dp"
    android:top="0dp"
    android:right="0dp"
    android:bottom="0dp" />
<corners android:radius="8dp" 
  android:bottomRightRadius="0dp" android:bottomLeftRadius="0dp" 
  android:topLeftRadius="8dp" android:topRightRadius="0dp"/>
<stroke android:width="2dp" android:color="#ff444444"/>
</shape>
  • 中央と右のボタンの形状は同じです。どのコーナーを丸めるかを試す必要があります。

そして最後に、ビューのレイアウト:

<TableRow android:id="@+id/buttonsRow"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"
    android:paddingTop="10dp">
    <RelativeLayout  android:id="@+id/buttonsRowRelativeLayout" 
        android:layout_height="wrap_content" 
        android:layout_width="match_parent">

    <Button
        android:id="@+id/leftButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/save"
        android:textColor="#ffffffff"
        android:background="@drawable/up_left_button_selector"
        android:layout_toLeftOf="@+id/centerButton" />
    <Button
        android:id="@+id/centerButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/change"
        android:textColor="#ffffffff"
        android:background="@drawable/up_center_button_selector" 
        android:layout_centerHorizontal="true"/>
    <Button
        android:id="@+id/rightButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/send"
        android:textColor="#ffffffff"
        android:background="@drawable/up_right_button_selector"
        android:layout_toRightOf="@+id/centerButton" />
    </RelativeLayout >      
</TableRow>

そして、それはかなりよさそうだ。

于 2013-02-28T10:03:17.760 に答える