Android操作栏按钮拉长了吗?

时间:2013-05-27 21:52:31

标签: android android-actionbar android-xml android-button

在我的android操作栏中我有2个自定义按钮生病后发布下面的代码,但我的问题是按钮在操作栏中拉伸如何设置它以适应文本而不是拉伸?这是我的代码

activity_main_ab.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="fill_horizontal"
android:orientation="horizontal" >
<LinearLayout 
    android:layout_alignParentLeft="true"
    android:layout_width="fill_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal">

    <Button
    android:id="@+id/action_bar_button_about"
    android:layout_width="fill_parent"
    android:layout_height="match_parent"           
    android:layout_weight="1"
    android:background="@drawable/ios_btn"
    android:text="about" />

    <Button
    android:id="@+id/action_bar_button_reload"
    android:layout_width="fill_parent"
    android:layout_height="match_parent" 
    android:background="@drawable/ios_btn"          
    android:layout_weight="1"
    android:text="reload" />
</LinearLayout>    
</RelativeLayout>

MainActivity.java

package jb.cydia;

import android.os.Bundle;
import android.app.ActionBar;
import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);   
    final ActionBar ab = getActionBar();
    ab.setDisplayShowHomeEnabled(false);
    ab.setDisplayShowTitleEnabled(false);     
    final LayoutInflater inflater =    (LayoutInflater)getSystemService("layout_inflater");
    View view = inflater.inflate(R.layout.activity_main_ab,null); 
    ab.setCustomView(view);
    ab.setDisplayShowCustomEnabled(true);

}
}

哦差点忘了它是android甚至看起来它的截图是来自ios ..我根据我的手机看起来像那个:)关于定制的机器人吗?

enter image description here

2 个答案:

答案 0 :(得分:1)

<Button
    android:layout_width="fill_parent"
... />

应该是

<Button
    android:layout_width="wrap_content"
... />

答案 1 :(得分:1)

您应该始终使用9个补丁图像作为按钮。检查this网站以创建9个补丁。另请查看this视频。