2016-12-05 9 views
-2

私のアプリではアイコンが動的にロードされ、アイコンスロットに自動フィットします。現在、アイコンのサイズは変更されていないので、高さはActionBarです。私はちょうどActivityからAppCompatActivityに移行して、できるだけ再利用したかったので、ToolBarの代わりにSupportActionBarを使用しています。 ActionBarにアイコンを自動的にフィットさせるには何ができますか?Android AppCompat SupportActionBar - 特定のサイズにアイコンを自動調整する方法

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/root_view_second_screen" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    style="?wallpaper" 
    android:orientation="vertical" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    tools:context="com.sarkms.cclib.SecondScreen" > 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1"> 
     <ListView 
      android:id="@+id/convView" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:divider="@android:color/transparent" 
      android:dividerHeight="10.0sp" 
      android:transcriptMode="normal" 
      android:smoothScrollbar="true" > 
     </ListView> 
     <TextView 
      android:id="@+id/lbl_MultiContactsPing_note" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerInParent="true" 
      android:layout_marginLeft="30dp" 
      android:layout_marginRight="30dp" 
      android:padding="10dp" 
      android:background="@drawable/lightblue_rounded_poll_title_bg" 
      android:visibility="gone" 
      android:text="@string/lbl_multiplecontacts_ping_note"    
      android:textSize="20sp" 
      android:textStyle="italic" 
      android:textColor="@color/grey_dark" /> 
    </RelativeLayout>   
    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="15sp" 
     android:layout_marginBottom="15sp" > 

     <ImageView 
      android:id="@+id/emoticon_btn" 
      android:layout_width="30sp" 
      android:layout_height="wrap_content" 
      android:layout_gravity="bottom" 
      android:src="@drawable/smiley" /> 

     <ImageView 
      android:id="@+id/impMsg" 
      android:layout_width="12dp" 
      android:layout_height="25dp" 
      android:layout_gravity="bottom" 
      android:padding="4dp" 
      android:layout_marginLeft="10dp" 
      android:layout_marginRight="10dp" 
      android:background="@drawable/imp_msg_unselected_5" /> 

     <ImageView 
      android:id="@+id/Send" 
      android:src="@drawable/sendping_7" 
      android:layout_width="35sp" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="15sp" 
      android:layout_marginRight="15sp" 
      android:layout_gravity="bottom" /> 
    </LinearLayout>    

+0

'AppCompatActivity'で' ToolBar'を使用することに問題はありますか? –

+0

アイコンを左揃えにするのではなく、真ん中に設定します。さらに、すべてのレイアウトxmlにツールバーを追加する必要があります。 SupportActionBarでこのサイズ変更を行うことができれば、レイアウトxmlに触れるのを避けることができます。 –

+0

アイコンとアクションバーを含むレイアウトファイルを投稿できますか? –

答えて

0

あなたが提供した情報は、あなたの問題に任意の正確な答えを与えるのに十分ではありません。しかし、私はあなたがアイコンスロットに修正したい1つのjpeg/pngイメージを持っていると思います。 達成する1つの方法は、その画像をビットマップに変換して、画像の高さと幅を調整することです。

Bitmap image = //load image from your source 
image = Bitmap.createScaledBitmap(image, iconSlotHeight, iconSlotWidth, true); 

この画像ビットマップを使用して、画像をアイコンスロットに塗りつぶします。

+0

アイコンスロットに自動スケールする方法はありませんか? ActionBarでどのように起こったのか? –

+0

私はActionBarで何が起こったのか分かりません。画面サイズに合わせて調整する必要があると思います。したがって、 'DisplayMetrices'を使って画面サイズを取得し、必要に応じて高さと幅を操作することができます。 – Shubham

関連する問題