Issue
My project includes 6 icons on tabLayout
. They all put to tabs
programmatically, not with ImageView
from layout
. Now, it must be increased size of this icons for tablet screen.
I tried so much things; tried increase icon size, tried layout_ width
and layout_height
of tabItems. But that's all didn't work.
How can I increase icons size on tabLayout? Hope someone can help me for this.
Result_Activity.java
private Integer[] images;
Integer[] domesticImages = {
R.drawable.ic_directions_bus_black_24dp,
R.drawable.ic_flight_takeoff_black_24dp,
R.drawable.ic_directions_boat_black_24dp,
R.drawable.ic_train_black_24dp,
R.drawable.ic_hotel,
R.drawable.ic_rent_a_car
};
private Integer[] domesticImagesClicked = {
R.drawable.ic_directions_bus_clicked_24dp,
R.drawable.ic_flight_takeoff_clicked_24dp,
R.drawable.ic_directions_boat_clicked_24dp,
R.drawable.ic_train_clicked_24dp,
R.drawable.ic_hotel_clicked,
R.drawable.ic_rent_a_car_clicked
};
activity_result.xml
<android.support.design.widget.TabLayout
android:id="@+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_below="@+id/rl_Detail"
android:background="#F4E6CA"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:tabBackground="?attr/selectableItemBackgroundBorderless"
app:tabIndicatorColor="@android:color/transparent"
app:tabPaddingEnd="15dp"
app:tabPaddingStart="15dp">
<android.support.design.widget.TabItem
android:id="@+id/tab1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:saveEnabled="true" />
<android.support.design.widget.TabItem
android:layout_width="wrap_content"
android:layout_height="match_parent" />
<android.support.design.widget.TabItem
android:layout_width="wrap_content"
android:layout_height="match_parent" />
<android.support.design.widget.TabItem
android:layout_width="wrap_content"
android:layout_height="match_parent" />
<android.support.design.widget.TabItem
android:layout_width="wrap_content"
android:layout_height="match_parent" />
<android.support.design.widget.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</android.support.design.widget.TabLayout>
Solution
If you want different icon sizes for different screen sizes you probably need to to any of these:
1 - Make different images with it's own right size and put in the respective folders, as android have drawable folders for each dpi density, take a look at: Android Studio: Drawable Folder: How to put Images for Multiple dpi?
2 - If the icons are simple, you can use vector icons, since they can change their size to fit any screen size you need. Take a look at: https://developer.android.com/studio/write/vector-asset-studio
3 - You can check if the device is an tablet and change the icons size programatically as well, that will depend on how you are adding the icons. You can check that using the following code:
public static boolean isTablet(Context context) {
return (context.getResources().getConfiguration().screenLayout & 0xF) >= 3;
}
or you can check for different ways of doing that here: Determine if the device is a smartphone or tablet?
If none of those methods helps, there is an official detailed guide: https://developer.android.com/guide/practices/screens_support.html#DeclaringTabletLayouts
Answered By - Ricardo A.
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.