0
이미지를 중심 제목으로하고 다른 이미지를 오른쪽 맞춤으로 사용자 지정 도구 모음을 만들었습니다. 필자는 상대적 레이아웃을 사용하여 이미지 뷰를 저장했습니다. 그러나 상대 레이아웃은 너비가 match_parent로 설정되어 있음에도 불구하고 도구 모음의 전체 길이를 포함하지 않는 것 같습니다. 다음과 같이 코드는 다음과 같습니다사용자 지정 도구 모음의 가운데 맞춤 제목
activity_main.xml
<android.support.v7.widget.Toolbar
android:id="@+id/app_bar"
android:minHeight="?attr/actionBarSize"
android:layout_height="?attr/actionBarSize"
android:layout_width="match_parent"
android:background="?attr/colorPrimary">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<ImageView
android:layout_width="150dp"
android:layout_height="30dp"
android:src="@drawable/title"
android:id="@+id/title_image"
android:layout_centerInParent="true" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/oie_transparent"
android:layout_alignParentRight="true"
android:id="@+id/cart_icon"
android:layout_toRightOf="@id/title_image"
android:layout_marginTop="2dp"
android:layout_marginLeft="30dp"
android:layout_marginBottom="2dp"/>
</RelativeLayout>
</android.support.v7.widget.Toolbar>
MainActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); // an example activity_main.xml is provided below
Toolbar tb = (Toolbar) findViewById(R.id.app_bar);
setSupportActionBar(tb);
}
는이 http://stackoverflow.com/questions/26533510/android-toolbar-center-title-and-custom-font – Meenaxi
그것은 상대 레이아웃과 여러 어린이를 포함하지 않는 참조 –