ツールバー内のテキストビューのセンタリングに問題があります。Android:テキストビューのツールバーがあまり集中していない
テキストは、テキストがわずかにあまりにも多くの右または左のナビゲーションアイコンにあるいくつかのパディングを持って見ることができるように、それはこの
のように見えますが長くなりすぎます。
下の画像は、テキストが小さい場合、オプションのロゴが(スパナがちょうど可視である場合、それは
同様微細で
にレイアウト境界を有していますプレースホルダ)、最初の画像に表示されたテキストがきれいに表示されます
ここにコードがあります。あなたが何かを見るために必要がある場合はコメントを残してください
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.ersen.toolbarcentreproblem.MainActivity">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
android:background="@color/colorPrimary">
<ImageView
android:id="@+id/logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:padding="10dp"
android:visibility="gone"
app:srcCompat="@drawable/ic_build_black_24dp"
tools:visibility="visible"/>
<TextView
android:text="Set Holiday Set Holiday Set Holiday Set Holiday"
android:textColor="@android:color/white"
android:textAllCaps="true"
android:layout_gravity="center"
android:maxLines="1"
android:ellipsize="end"
android:gravity="center"
android:textSize="18sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</android.support.v7.widget.Toolbar>
<TextView
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Hello World!" />
</LinearLayout>
私が試してみました何
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar)findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayShowTitleEnabled(false);
toolbar.setNavigationIcon(R.drawable.ic_menu);
}
}
MainActivity
-
ツールバーの0dpに設定されているすべてのは、何の効果
- contentInsetLeft
- contentInsetRight
- contentInsetEnd
- contentInsertStart
がありませんでした
は、私はまた、テキストビューにパディングを適用しようとしたが、テキストがあるとき、これは問題の原因となりました小さい。
編集1:しようとナレンドラSorathiyaソリューション
この多くを模索するためには、単に 'invisible'の代わりに、' gone'にあなたの '' logo' ImageView'の 'visibility'を設定します。 –
@MikeM。こんにちは返信ありがとうございます。これはいくつかのケースでは機能するかもしれませんが、私は膨らんだメニューを持っているかもしれません。 –
'SET HOLIDAY'' TextView'幅を' match_parent'に変更してください。 – Ironman