2017-10-26 23 views
1

私はXamarin pclを働いています。今Androidのプロジェクトには、ツールバーとタブバーの自動レンダリングレイアウトがあります。私はtoolbar.axmlを中心にアイコンを持つようにカスタマイズしています。すべてのページが戻るボタン(私は推測するナビゲーションページの属性)を終了するまで、それはもはやツールバーの唯一のものではないので、アイコンが右に移動するすべてが終了します。アイコンを固定位置にする簡単な修正はありますか?戻るボタンは、axmlでは宣言されていませんが、Xamarin.Formsの新しいNavigationPage()関数によって生成されます。ツールバーの中央に画像を固定するAndroid

マイAXMLは次のように今見える:私はすでにアンドロイドの使用を検討

<?xml version="1.0" encoding="utf-8"?> 
<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:background="#72B1A2" 
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
    android:popupTheme="@style/ThemeOverlay.AppCompat.Light" 
    > 
    <ImageView 
    android:id="@id/image" 
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content" 
    android:paddingTop="5dp" 
    android:paddingBottom="5dp" 
    android:layout_gravity="center" 
    android:baselineAlignBottom="true" 
    android:scaleType="fitCenter" 
    android:src="@drawable/ictzaak_FC" 
    /> 

</android.support.v7.widget.Toolbar> 

:layout_gravity = "センター" とAndroid:layout_gravity = "center_horizo​​ntal" とAndroid:center_horizo​​ntalか何かが、それはdidnのトン、それがどのように見えるか、それ

を修正: Startup screen without the return button

With return button and out of center

+0

あなたのツールバーに継承されたスタイルは、あなたのxmlでのオーバーライドはあなたにこれを追加することであることを確認してアプリ、ツールバー" – AbuQauod

+0

どこに追加しますか?マニフェストまたはtoolbar.axmlにありますか? – ICTzaakDEV

+0

AbuQauod

答えて

0

Y RelativeLayoutにイメージをネストしようとする可能性があります。そして、この中でイメージを中央に置くことができます。このように:

<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:background="#72B1A2" 
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
    android:popupTheme="@style/ThemeOverlay.AppCompat.Light" 
    > 
    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 
     <ImageView 
      android:id="@id/image" 
      android:layout_height="wrap_content" 
      android:layout_width="wrap_content" 
      android:paddingTop="5dp" 
      android:paddingBottom="5dp" 
      android:layout_centerInParent="true" 
      android:baselineAlignBottom="true" 
      android:scaleType="fitCenter" 
      android:src="@drawable/ictzaak_FC" 
      /> 
    </RelativeLayout> 


</android.support.v7.widget.Toolbar> 
+0

それは動作するはずですが、私はそれがうまくないと思うこれは、バックボタンウィジェットがrelativelayoutの左側に追加され、そのすべてが右側に移動したためです。 xamarin形式のpclをクラッシュさせずに、同じaxmlでバックボタンを定義することはできますか? – ICTzaakDEV

+0

@ICTzaakDEVまあ、私はXamarinの専門家ではない。しかし、あなたがバックボタンの幅を知っていれば、アンドロイドを設定することができます:layout_marginLeft = " - buttonWidth"イメージ。 – user6586661

+0

どうもありがとう、私はそのようなものを作ろうとしています! – ICTzaakDEV

0

イメージはLinearLayoutを使用して中央に設定されます。 contentInsetStart =「0dp」 アプリ: アプリcontentInsetEndWithActions =「0dp」:contentInsetStartWithNavigation = "0dp

<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:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
      android:popupTheme="@style/ThemeOverlay.AppCompat.Light"> 

      <LinearLayout 
       android:layout_width="match_parent" 
       android:orientation="vertical" 
       android:gravity="center" 
       android:layout_height="match_parent"> 

       <ImageView 
        android:id="@id/image" 
        android:layout_height="wrap_content" 
        android:layout_width="wrap_content" 
        android:padding="5dp" 
        android:scaleType="fitCenter" 
        android:src="@drawable/ic_img"/> 
      </LinearLayout> 

     </android.support.v7.widget.Toolbar> 
+0

戻るボタンは線形レイアウトの前に動的に追加されます。つまり、ナビゲーションページがXamarinフォームでどのように機能するかです。このように固定されているよりも、線形レイアウトで追加されている場合 – ICTzaakDEV

関連する問題