① android 怎样设置title 居中显示
1在onCreate()方法中加上这三句话:
[java] view plain
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.main);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.title);
在布局文件中新建一个title.xml文件:
[java] view plain
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http //schemas android com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center">
<TextView android:id="@+id/textTile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="title" />
</LinearLayout>
② android studio 开发的app怎样使标题内的文字居中显示,麻烦说得详细点,O(∩_∩)O谢谢
在xml布局文件中,把标题文字的TextView加入一行属性:
android:gravity="center"
例子:
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="居中显示"/>
③ android 怎么让toolbar上面的title居中
自带的settitle是居左的,可以自定义一个textview,如下方式:
Android自带的toolbar有设置title的功能,但是设置的title都是居左的,但是很多需求都是要title居中,主要的方法就是:不使用setTitle,而是在toolBar的xml定义中插入一个TextView,然后设置其layout_gravity为center,它就在正中间了。。
1、定义toolbar的xml文件
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:background="@color/primary">
<TextView
android:id="@+id/toolbar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:singleLine="true"
android:textColor="@color/white"
android:textSize="20sp" />
</android.support.v7.widget.Toolbar>
具体代码中使用toolbar
public Toolbar initToolbar(int id, int titleId, int titleString) {
Toolbar toolbar = (Toolbar) findViewById(id);
// toolbar.setTitle("");
TextView textView = (TextView) findViewById(titleId);
textView.setText(titleString);
setSupportActionBar(toolbar);
android.support.v7.app.ActionBar actionBar = getSupportActionBar();
if (actionBar != null){
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowTitleEnabled(false);
}
return toolbar;
}
④ android如何让标题栏文字居中.不用自定义
可以先隐藏标题栏,在AndroidManifest里的对应的activity标签里添加:android:theme="@android:style/Theme.Black.NoTitleBar"
然后在对应的layout布局里添加一个TextView当做标题,设置文字居中
⑤ android 中字体居中怎么设置
有2种方法可以设置TextView文字居中:
一:在xml文件设置:Android:gravity="center"
二:在程序中设置:m_TxtTitle.setGravity(Gravity.CENTER);
⑥ 安卓里面Listview 里的文字怎么实现居中显示(只有简单的一个Listview 没有其他控件
具体代码如下(不过我的是ListActivity,你的ListView控件,二者用法没太大区别)
这种方式是实现自定义显示模式的典型用法。
//在res中定义:list_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<TextView
android:id="@+id/title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
/>
</LinearLayout>
//上面android:gravity="center_horizontal" 是居中的关键
//在主类中借助SimpleAdapter适配器
public class MainActivity extends ListActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SimpleAdapter adapter = new SimpleAdapter(this, getData(),
R.layout.list_layout, new String[] { "title" },
new int[] { R.id.title});
setListAdapter(adapter);
}
private List<Map<String, Object>> getData() {
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
Map<String, Object> map = new HashMap<String, Object>();
map.put("title", "AAAAA");
list.add(map);
map = new HashMap<String, Object>();
map.put("title", "BBBB");
list.add(map);
map = new HashMap<String, Object>();
map.put("title", "CC");
list.add(map);
return list;
}
}
⑦ android 九宫格怎么居中显示 下面的我用android:gravity="center" 这个属性老居中不了。
Android九宫格显示控件,通常是用GridView,GridView多行多列网状形式的显示控件,而使GridView Item水平居中需要设置两点
GridView中设置属性android:gravity="center"
在其item布局文件中设置LinearLayout的属性android:gravity="center"(通常没有居中,都是因为Item的布局没有设置)
关于GridView的常用设置:
android:numColumns="auto_fit" --------列数设置为自动
android:columnWidth="90dp",----------每列的宽度,也就是Item的宽度
android:stretchMode="columnWidth"------缩放与列宽大小同步
android:verticalSpacing="10dp"----------垂直边距
android:horizontalSpacing="10dp"-------水平边距
⑧ Android自定义标题栏,如何使标题栏文字居中
设置ViewGroup为RelativeLayout,然后android:layout_centerInParent="true"