4

背景グラデーションのあるボタンで小さいテキスト サイズを使用すると、ボタンは Android 2.2 では期待どおりに縮小されますが、Android 4 では縮小されません。ボタンを機能させる唯一の方法は、ボタンを TextView に変換し、クリック イベントを設定することです。その上で。この問題を抱えている TextView についての言及を見てきましたが、それらは期待どおりに機能します。

Android 2.2 携帯電話では期待どおりに動作するのを見てきましたが、Android 4.0.4 携帯電話と Android 4.2.2 エミュレーターではボタンがフルハイトのままです。

私が間違っているかもしれないことを教えてください。この例では、Eclipse (Juno) の新しいアプリ ウィザードのすべてのデフォルトを使用します。

注:私が使用していた実際のアプリの場合

アンドロイド:パディング="4dp"
TextView の見栄えを良くしました (ボタンには影響しませんでした) が、この例では問題を誇張するために 0dp を使用しました。

activity_main.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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:orientation="vertical"
    tools:context=".MainActivity" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/button_gradient"
        android:text="@string/hello_world" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="12sp"
        android:background="@drawable/button_gradient"
        android:text="@string/hello_world" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="0dp"
        android:textSize="12sp"
        android:background="@drawable/button_gradient"
        android:text="@string/hello_world" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="0dp"
        android:textSize="12sp"
        android:background="@drawable/button_gradient"
        android:text="@string/hello_world" />
</LinearLayout>

button_gradient.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <gradient
        android:startColor="#0000BB"
        android:endColor="#E0E0E0"
        android:angle="90"/>
        <corners android:radius="10dp" />
</shape>

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.test"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.test.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>
4

1 に答える 1

0

LinearLayout を使用する代わりに、RelativeLayout を使用できます。

<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"
android:padding="20dp"
android:layout_margin="10dp"
android:orientation="vertical"
tools:context=".MainActivity" >

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/textView1"
    android:gravity="center"
    android:layout_alignLeft="@+id/button1"
    android:layout_alignRight="@+id/button1"
    android:text="@string/hello_world" />

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/button1"
    android:layout_below="@+id/textView1"
    android:background="@drawable/button_gradient"
    android:text="@string/hello_world" />

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="12sp"
    android:id="@+id/button2"
    android:layout_below="@+id/button1"
     android:layout_alignLeft="@+id/button1"
    android:layout_alignRight="@+id/button1"
    android:background="@drawable/button_gradient"
    android:text="@string/hello_world" />

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:padding="0dp"
    android:textSize="12sp"
    android:id="@+id/button3"
     android:layout_alignLeft="@+id/button1"
    android:layout_alignRight="@+id/button1"
    android:layout_below="@+id/button2"
    android:background="@drawable/button_gradient"
    android:text="@string/hello_world" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:padding="10dp"
    android:textSize="12sp"
    android:layout_below="@+id/button3"
    android:layout_alignLeft="@+id/button1"
    android:layout_alignRight="@+id/button1"
    android:background="@drawable/button_gradient"
    android:text="@string/hello_world" />

于 2013-05-26T06:04:54.390 に答える