Android: 支持ActionBar的ProgressBar如何居中显示
Android: How to display centered ProgressBar in support ActionBar
试图在我的 activity 的标题栏中显示一个进度条,但我正在努力如何使其整齐居中。
到目前为止我的代码:
进度条布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="fill_horizontal" >
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:progress="50" />
</RelativeLayout>
Activity布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="@+id/activity_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</android.support.v7.widget.Toolbar>
</LinearLayout>
Java代码:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view);
Toolbar myToolbar = (Toolbar) findViewById(R.id.activity_toolbar);
setSupportActionBar(myToolbar);
getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_CUSTOM);
View progress = getLayoutInflater().inflate(R.layout.progressbar_layout, null);
getSupportActionBar().setCustomView(progress);
}
很简单,但结果很糟糕,整个事情看起来很奇怪......
Screenshot of uncentered progressbar
布局检查器中的相同内容
Screenshot of layout inspector with uncentered progressbar
知道如何进行吗?
除了菜单和后退箭头,我不需要任何其他操作栏功能。是否可以按照预期行为分别显示这些控件? (这很复杂,尤其是溢出菜单)
或者是否可以更改 ActionBar 样式,使两侧具有相同的大小(AND padding/margin)?
想法?
okey ..检查我对这个问题的回答..我认为这可能对你有帮助 Title bar
试图在我的 activity 的标题栏中显示一个进度条,但我正在努力如何使其整齐居中。
到目前为止我的代码:
进度条布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="fill_horizontal" >
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:progress="50" />
</RelativeLayout>
Activity布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="@+id/activity_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</android.support.v7.widget.Toolbar>
</LinearLayout>
Java代码:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view);
Toolbar myToolbar = (Toolbar) findViewById(R.id.activity_toolbar);
setSupportActionBar(myToolbar);
getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_CUSTOM);
View progress = getLayoutInflater().inflate(R.layout.progressbar_layout, null);
getSupportActionBar().setCustomView(progress);
}
很简单,但结果很糟糕,整个事情看起来很奇怪......
Screenshot of uncentered progressbar
布局检查器中的相同内容
Screenshot of layout inspector with uncentered progressbar
知道如何进行吗?
除了菜单和后退箭头,我不需要任何其他操作栏功能。是否可以按照预期行为分别显示这些控件? (这很复杂,尤其是溢出菜单)
或者是否可以更改 ActionBar 样式,使两侧具有相同的大小(AND padding/margin)?
想法?
okey ..检查我对这个问题的回答..我认为这可能对你有帮助 Title bar