Hello!
The question is the following, I want to do with the landscape orientation of the menu screen on the left of five points, using standard methods it does not work well with scaling and decided to do it as follows. Vertical LinearLayout is divided into five identical LinearLayout or RelativeLayout and in each cell is placed in a rectangle occupying the volume of the entire cell and divided into two halves, the lower half with text and a fixed height, the upper half contains a picture that fills the entire volume. Also in the lower and upper parts there will be a background or it will be better to make it in LinearLayout or RelativeLayout where there will be rectangles, pictures with a transparent background. How best to implement this?
Maybe through Bitmap or a separate XML file and insert through merge .... Tell me, please, if you can with an example. This is all done in order that at different resolutions the picture would normally scale and nothing would get to the bottom. It is possible that the picture was just centered in its cell
Here is my code that I change
<LinearLayout android:orientation="vertical" android:layout_width="wrap_content" android:layout_height="fill_parent" android:background="@drawable/bg_button2"> <TextView android:layout_width="fill_parent" android:layout_height="33dp" android:background="@drawable/bg_header"/> <RelativeLayout android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_weight="0.2"> <Button android:id="@+id/homeButton" android:layout_width="55dp" android:layout_height="wrap_content" android:drawableTop="@drawable/ic_home_g" android:background="@drawable/bg_button2" android:textColor="#FFF" android:textSize="10dp" android:text="@string/str_base_activity_toolbar_home"/> </RelativeLayout> <RelativeLayout android:layout_width="55dp" android:layout_height="fill_parent" android:layout_weight="0.2"> <Button android:id="@+id/assignedButton" android:layout_width="fill_parent" android:layout_height="wrap_content" android:drawableTop="@drawable/ic_trailer_inspection_g" android:background="@drawable/bg_button2" style="@style/buttonFont" android:text="@string/str_base_activity_toolbar_assigned"/> <TextView android:id="@+id/assignedButtonCounter" android:layout_alignTop="@id/assignedButton" android:layout_alignRight="@id/assignedButton" android:text="2" android:visibility="gone" style="@style/buttonBadge"/> </RelativeLayout> <RelativeLayout android:layout_width="55dp" android:layout_height="fill_parent" android:layout_weight="0.2"> <Button android:id="@+id/availableButton" android:layout_width="fill_parent" android:layout_height="wrap_content" android:drawableTop="@drawable/ic_available_g" android:background="@drawable/bg_button2" style="@style/buttonFont" android:text="@string/str_base_activity_toolbar_available"/> <TextView android:id="@+id/availableButtonCounter" android:layout_alignTop="@id/availableButton" android:layout_alignRight="@id/availableButton" android:text="2234" android:visibility="gone" style="@style/buttonBadge"/> </RelativeLayout> <RelativeLayout android:layout_width="55dp" android:layout_height="fill_parent" android:layout_weight="0.2"> <Button android:id="@+id/completedButton" android:layout_width="fill_parent" android:layout_height="wrap_content" android:drawableTop="@drawable/ic_completed_g" android:background="@drawable/bg_button2" style="@style/buttonFont" android:text="@string/str_base_activity_toolbar_completed"/> </RelativeLayout> <RelativeLayout android:layout_width="55dp" android:layout_height="fill_parent" android:layout_weight="0.2"> <Button android:id="@+id/mailButton" android:layout_width="fill_parent" android:layout_height="wrap_content" android:drawableTop="@drawable/ic_mail_g" android:background="@drawable/bg_button2" style="@style/buttonFont" android:text="@string/str_base_activity_toolbar_mail"/> <TextView android:id="@+id/mailButtonCounter" android:layout_alignTop="@id/mailButton" android:layout_alignRight="@id/mailButton" android:text="2" android:visibility="gone" style="@style/buttonBadge"/> </RelativeLayout> </LinearLayout>
Did I understand correctly, I have an activation code (this is a piece of code)
public enum ButtonType { Home, AssignedLoads, AvailableLoads, CompletedLoads, Mail } tv_title = (TextView)findViewById(R.id.tv_title); private Button homeButton; private Button assignedButton; private Button availableButton; private Button completedButton; private Button mailButton; private TextView assignedButtonCounter; private TextView availableButtonCounter; private TextView mailButtonCounter; private LinearLayout parentLinearLayout; public void onCreate(Bundle savedInstanceState) { Log.d(LOG_TAG, "onCreate"); requestWindowFeature(Window.FEATURE_NO_TITLE); super.onCreate(savedInstanceState); setContentView(R.layout.base_activity); //buttons homeButton = (Button)findViewById(R.id.homeButton); assignedButton = (Button)findViewById(R.id.assignedButton); availableButton = (Button)findViewById(R.id.availableButton); completedButton = (Button)findViewById(R.id.completedButton); mailButton = (Button)findViewById(R.id.mailButton); //Counters assignedButtonCounter = (TextView)findViewById(R.id.assignedButtonCounter); availableButtonCounter = (TextView)findViewById(R.id.availableButtonCounter); mailButtonCounter = (TextView)findViewById(R.id.mailButtonCounter); parentLinearLayout = (LinearLayout)findViewById(R.id.parentLinearLayout); homeButton.setOnClickListener(listenerToolBar_OnClick); assignedButton.setOnClickListener(listenerToolBar_OnClick); availableButton.setOnClickListener(listenerToolBar_OnClick); completedButton.setOnClickListener(listenerToolBar_OnClick); mailButton.setOnClickListener(listenerToolBar_OnClick); setBadges(); } void setActiveButton(ButtonType button, boolean bEnabled) { Resources resources = getResources(); Button b; switch (button) { case AssignedLoads: b = assignedButton; b.setCompoundDrawablesWithIntrinsicBounds(null, resources.getDrawable(R.drawable.ic_trailer_inspection), null, null ); break; case AvailableLoads: b = availableButton; b.setCompoundDrawablesWithIntrinsicBounds(null, resources.getDrawable(R.drawable.ic_available), null, null); break; case CompletedLoads: b = completedButton; b.setCompoundDrawablesWithIntrinsicBounds(null, resources.getDrawable(R.drawable.ic_completed), null, null); break; case Mail: b = mailButton; b.setCompoundDrawablesWithIntrinsicBounds(null, resources.getDrawable(R.drawable.ic_mail), null, null); break; default: b = homeButton; b.setCompoundDrawablesWithIntrinsicBounds(null, resources.getDrawable(R.drawable.ic_home), null, null); break; } b.setBackgroundResource(R.drawable.bg_button_selected); b.setClickable(bEnabled); } void setBadges() { Integer count = MailItemData.getUnreadMailCount(getApplicationContext()); mailButtonCounter.setText(count.toString()); mailButtonCounter.setVisibility(count > 0 ? View.VISIBLE : View.GONE); count = TripData.getNewAvailableLoadsCount(getApplicationContext()); availableButtonCounter.setText(count.toString()); availableButtonCounter.setVisibility(count > 0 ? View.VISIBLE : View.GONE); count = TripData.getAssignedLoadsCount(getApplicationContext()); assignedButtonCounter.setText(count.toString()); assignedButtonCounter.setVisibility(count > 0 ? View.VISIBLE : View.GONE); } }
I change it like this:
public enum ButtonType { Home, AssignedLoads, AvailableLoads, CompletedLoads, Mail } tv_title = (TextView)findViewById(R.id.tv_title); private ImageView homeButton; private ImageView assignedButton; private ImageView availableButton; private ImageView completedButton; private ImageView mailButton; private TextView assignedButtonCounter; private TextView availableButtonCounter; private TextView mailButtonCounter; private LinearLayout parentLinearLayout; public void onCreate(Bundle savedInstanceState) { Log.d(LOG_TAG, "onCreate"); requestWindowFeature(Window.FEATURE_NO_TITLE); super.onCreate(savedInstanceState); setContentView(R.layout.base_activity); //ImageViews homeButton = (ImageView)findViewById(R.id.homeButton); assignedButton = (ImageView)findViewById(R.id.assignedButton); availableButton = (ImageView)findViewById(R.id.availableButton); completedButton = (ImageView)findViewById(R.id.completedButton); mailButton = (ImageView)findViewById(R.id.mailButton); //Counters assignedButtonCounter = (TextView)findViewById(R.id.assignedButtonCounter); availableButtonCounter = (TextView)findViewById(R.id.availableButtonCounter); mailButtonCounter = (TextView)findViewById(R.id.mailButtonCounter); parentLinearLayout = (LinearLayout)findViewById(R.id.parentLinearLayout); homeButton.setOnClickListener(listenerToolBar_OnClick); assignedButton.setOnClickListener(listenerToolBar_OnClick); availableButton.setOnClickListener(listenerToolBar_OnClick); completedButton.setOnClickListener(listenerToolBar_OnClick); mailButton.setOnClickListener(listenerToolBar_OnClick); setBadges(); } void setActiveButton(ButtonType ImageView, boolean bEnabled) { Resources resources = getResources(); Button b; switch (ImageView) { case AssignedLoads: b = assignedButton; ImageView b = new ImageView(context); b.setImageResource(R.drawable.ic_trailer_inspection); b.setLayoutParams(new GridView.LayoutParams(10, 10)); b.setScaleType(ImageView.ScaleType.FIT_CENTER); b.setPadding(1, 1, 1, 1); break; case AvailableLoads: b = availableButton; b.setImageResource(R.drawable.ic_available); b.setLayoutParams(new GridView.LayoutParams(10, 10)); b.setScaleType(ImageView.ScaleType.FIT_CENTER); b.setPadding(1, 1, 1, 1); break; case CompletedLoads: b = completedButton; b.setImageResource(R.drawable.ic_completed); b.setLayoutParams(new GridView.LayoutParams(10, 10)); b.setScaleType(ImageView.ScaleType.FIT_CENTER); b.setPadding(1, 1, 1, 1); break; case Mail: b = mailButton; b.setImageResource(R.drawable.ic_mail); b.setLayoutParams(new GridView.LayoutParams(10, 10)); b.setScaleType(ImageView.ScaleType.FIT_CENTER); b.setPadding(1, 1, 1, 1); break; default: b = homeButton; b.setImageResource(R.drawable.ic_home); b.setLayoutParams(new GridView.LayoutParams(10, 10)); b.setScaleType(ImageView.ScaleType.FIT_CENTER); b.setPadding(1, 1, 1, 1); break; } b.setBackgroundResource(R.drawable.bg_button_selected); b.setClickable(bEnabled); } void setBadges() { Integer count = MailItemData.getUnreadMailCount(getApplicationContext()); mailButtonCounter.setText(count.toString()); mailButtonCounter.setVisibility(count > 0 ? View.VISIBLE : View.GONE); count = TripData.getNewAvailableLoadsCount(getApplicationContext()); availableButtonCounter.setText(count.toString()); availableButtonCounter.setVisibility(count > 0 ? View.VISIBLE : View.GONE); count = TripData.getAssignedLoadsCount(getApplicationContext()); assignedButtonCounter.setText(count.toString()); assignedButtonCounter.setVisibility(count > 0 ? View.VISIBLE : View.GONE); } }
And now in the XML file, replace the button with ImageView
(of course, with a little code editing)
I understood correctly ???