2017-08-10 25 views
0

私はtablayoutとviewpagerを作ったし、サーバーから完全にうまくいっているアイコンを表示するためにカスタムビューを使いましたが、完全に表示されていないタブアイコンは.iが写真をアップロードしました。この問題を解決する方法。私は50dpのような親や静的なサイズのイメージの高さの幅の一致を試してきましたが、何も動作しません。tablayoutアイコンを各タブスペースに大きくフィットさせる方法は?

私tablayout:アイコンの

<android.support.v4.view.ViewPager 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/smileyShowViewPagerId" 
     android:background="#ececec" 
     > 
     <android.support.design.widget.TabLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:id="@+id/tabLayoutId" 
      android:background="#99a4b1" 
      app:tabTextColor="#000000" 
      app:tabMode="fixed" 
      app:tabIndicatorColor="#6259b3" 
      > 
     </android.support.design.widget.TabLayout> 
    </android.support.v4.view.ViewPager> 

カスタムレイアウト:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/imageId_tabIcon" 
     android:layout_gravity="center" 
     /> 
</LinearLayout> 

、誰もが、私はAndroidのチュートリアルサイトを検索し、あまりにもグーグルで検索しないが、そこには解決している。この問題で私を助けることができるしてください。 enter image description here

私がしなければ、アイコンのサイズ24dpまたは他のアイコンがPIC enter image description here

+0

カスタムレイアウトを投稿してください。また、tablayout重力を 'fill'に設定します – Piyush

+0

重力を設定しました。しかし動作しませんでした。 と私は上記のコードを編集しました – AAA

答えて

0

変更

<ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/imageId_tabIcon" 
     android:layout_gravity="center" 
     /> 

<ImageView 
     android:layout_width="24dp" 
     android:layout_height="24dp" 
     android:id="@+id/imageId_tabIcon" 
     android:layout_gravity="center" 
     /> 

するには、編集回答以下のように示してスタート は、カスタムでこれを試してみてくださいレイアウト

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 

    <ImageView 
     android:id="@+id/icon2" 
     android:layout_width="20dp" 
     android:layout_height="20dp" 
     android:layout_centerHorizontal="true" /> 

    <TextView 
     android:id="@+id/text1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/icon2" 
     android:layout_centerHorizontal="true" 
     android:layout_marginTop="3dp" 
     android:textColor="@drawable/tab_text_color" 
     android:textSize="12dp" /> 

</RelativeLayout> 

ツアーコードで

private void setupTabIcons() { 

     /*tabLayout.getTabAt(0).setIcon(R.drawable.icon_tab1_config); 
     tabLayout.getTabAt(1).setIcon(R.drawable.icon_tab2_config); 
     tabLayout.getTabAt(2).setIcon(R.drawable.icon_tab3_config); 
     tabLayout.getTabAt(3).setIcon(R.drawable.icon_tab4_config); 
     tabLayout.getTabAt(4).setIcon(R.drawable.icon_tab5_config);*/ 


     View view = LayoutInflater.from(this).inflate(R.layout.tab_indicator_two, null); 
     ((ImageView) view.findViewById(R.id.icon2)).setImageResource(R.drawable.icon_tab1_config); 


     View view2 = LayoutInflater.from(this).inflate(R.layout.tab_indicator_two, null); 
     ((ImageView) view2.findViewById(R.id.icon2)).setImageResource(R.drawable.icon_tab2_config); 


     View view3 = LayoutInflater.from(this).inflate(R.layout.tab_indicator_two, null); 
     ((ImageView) view3.findViewById(R.id.icon2)).setImageResource(R.drawable.icon_tab3_config); 


     View view4 = LayoutInflater.from(this).inflate(R.layout.tab_indicator_two, null); 
     ((ImageView) view4.findViewById(R.id.icon2)).setImageResource(R.drawable.icon_tab4_config); 


     View view5 = LayoutInflater.from(this).inflate(R.layout.tab_indicator_two, null); 
     ((ImageView) view5.findViewById(R.id.icon2)).setImageResource(R.drawable.icon_tab5_config); 


     tabLayout.getTabAt(0).setCustomView(view); 
     tabLayout.getTabAt(1).setCustomView(view2); 
     tabLayout.getTabAt(2).setCustomView(view3); 
     tabLayout.getTabAt(3).setCustomView(view4); 
     tabLayout.getTabAt(4).setCustomView(view5); 

    } 
+0

あなたが言ったように私はしている間に私は質問を編集しました – AAA

+0

私は答えを編集しました。あなたの問題が解決されることを願っています。 –

+0

同じ結果:(。、。,, – AAA

関連する問題