android - Scaling the Image button in an included layout -


i have layout purely numeric keys , include in layout. problem, these keys scale in width when change orientation or place other lements next it.

my includable keys xml:

<?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="wrap_content">  <linearlayout android:layout_width="match_parent"               android:layout_height="wrap_content"               android:orientation="horizontal"               android:weightsum="3">      <button android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:id="@+id/btn_numeric_7"             android:text="@string/numeric_7"             android:textsize="@dimen/textsize_numeric_keys"             android:textcolor="@color/numeric_button_text_color"             android:background="@drawable/btn_register_main"             android:layout_margin="@dimen/main_buttons_margin"             android:layout_weight="1"             android:layout_gravity="center_vertical"/>      <button android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:id="@+id/btn_numeric_8"             android:text="@string/numeric_8"             android:textsize="@dimen/textsize_numeric_keys"             android:textcolor="@color/numeric_button_text_color"             android:background="@drawable/btn_register_main"             android:layout_margin="@dimen/main_buttons_margin"             android:layout_weight="1"             android:layout_gravity="center_vertical"/>      <button android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:id="@+id/btn_numeric_9"             android:text="@string/numeric_9"             android:textsize="@dimen/textsize_numeric_keys"             android:textcolor="@color/numeric_button_text_color"             android:background="@drawable/btn_register_main"             android:layout_margin="@dimen/main_buttons_margin"             android:layout_weight="1"             android:layout_gravity="center_vertical"/>   </linearlayout>  <linearlayout android:layout_width="match_parent"               android:layout_height="wrap_content"               android:orientation="horizontal"               android:weightsum="3">       <button android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:id="@+id/btn_numeric_4"             android:text="@string/numeric_4"             android:textsize="@dimen/textsize_numeric_keys"             android:textcolor="@color/numeric_button_text_color"             android:background="@drawable/btn_register_main"             android:layout_margin="@dimen/main_buttons_margin"             android:layout_weight="1"             android:layout_gravity="center_vertical"/>      <button android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:id="@+id/btn_numeric_5"             android:text="@string/numeric_5"             android:textsize="@dimen/textsize_numeric_keys"             android:textcolor="@color/numeric_button_text_color"             android:background="@drawable/btn_register_main"             android:layout_margin="@dimen/main_buttons_margin"             android:layout_weight="1"             android:layout_gravity="center_vertical"/>      <button android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:id="@+id/btn_numeric_6"             android:text="@string/numeric_6"             android:textsize="@dimen/textsize_numeric_keys"             android:textcolor="@color/numeric_button_text_color"             android:background="@drawable/btn_register_main"             android:layout_margin="@dimen/main_buttons_margin"             android:layout_weight="1"             android:layout_gravity="center_vertical"/>  </linearlayout>  <linearlayout android:layout_width="match_parent"               android:layout_height="wrap_content"               android:orientation="horizontal"               android:weightsum="3">       <button android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:id="@+id/btn_numeric_1"             android:text="@string/numeric_1"             android:textsize="@dimen/textsize_numeric_keys"             android:textcolor="@color/numeric_button_text_color"             android:background="@drawable/btn_register_main"             android:layout_margin="@dimen/main_buttons_margin"             android:layout_weight="1"             android:layout_gravity="center_vertical"/>      <button android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:id="@+id/btn_numeric_2"             android:text="@string/numeric_2"             android:textsize="@dimen/textsize_numeric_keys"             android:textcolor="@color/numeric_button_text_color"             android:background="@drawable/btn_register_main"             android:layout_margin="@dimen/main_buttons_margin"             android:layout_weight="1"             android:layout_gravity="center_vertical"/>      <button android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:id="@+id/btn_numeric_3"             android:text="@string/numeric_3"             android:textsize="@dimen/textsize_numeric_keys"             android:textcolor="@color/numeric_button_text_color"             android:background="@drawable/btn_register_main"             android:layout_margin="@dimen/main_buttons_margin"             android:layout_weight="1"             android:layout_gravity="center_vertical"/>  </linearlayout>  <linearlayout android:layout_width="match_parent"               android:layout_height="wrap_content"               android:orientation="horizontal"               android:weightsum="3">       <button android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:id="@+id/btn_numeric_x"             android:text="@string/numeric_x"             android:textsize="@dimen/textsize_numeric_keys"             android:textcolor="@color/numeric_button_text_color"             android:background="@drawable/btn_register_main"             android:layout_margin="@dimen/main_buttons_margin"             android:layout_weight="1"             android:layout_gravity="center_vertical"/>      <button android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:id="@+id/btn_numeric_0"             android:text="@string/numeric_0"             android:textsize="@dimen/textsize_numeric_keys"             android:textcolor="@color/numeric_button_text_color"             android:background="@drawable/btn_register_main"             android:layout_margin="@dimen/main_buttons_margin"             android:layout_weight="1"             android:layout_gravity="center_vertical"/>      <button android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:id="@+id/btn_numeric_dot"             android:text="@string/numeric_dot"             android:textsize="@dimen/textsize_numeric_keys"             android:textcolor="@color/numeric_button_text_color"             android:background="@drawable/btn_register_main"             android:layout_margin="@dimen/main_buttons_margin"             android:layout_weight="1"             android:layout_gravity="center_vertical"/>  </linearlayout> 

the xml including in not resize height of buttons, hides lower keys wich there no space

<linearlayout xmlns:android="http://schemas.android.com/apk/res/android"           xmlns:tools="http://schemas.android.com/tools"           android:layout_width="match_parent"           android:layout_height="match_parent"           android:background="@color/background_color"           android:orientation="vertical"           android:weightsum="3"           tools:context="fragments.registerfragments.drawerregisterfragment">  <imageview android:layout_width="match_parent"            android:layout_height="0dp"            android:layout_weight="1"            android:src="@drawable/bomb_icon"/>  <include layout="@layout/includable_view_numeric_keys"          android:layout_weight="2"          android:layout_height="wrap_content"          android:layout_width="wrap_content"/> 

oke, found problem, should have made linear layouts hold buttons jave hight of 0dp, , let layoutweight take care of it. here new xml:

<?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:weightsum="4"           android:layout_height="wrap_content">  <linearlayout android:layout_width="match_parent"               android:layout_height="0dp"               android:layout_weight="1"               android:orientation="horizontal"               android:weightsum="3">      <button android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:id="@+id/btn_numeric_7"             android:text="@string/numeric_7"             android:textsize="@dimen/textsize_numeric_keys"             android:textcolor="@color/numeric_button_text_color"             android:background="@drawable/btn_register_main"             android:layout_margin="@dimen/main_buttons_margin"             android:layout_weight="1"             android:layout_gravity="center_vertical"/>      <button android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:id="@+id/btn_numeric_8"             android:text="@string/numeric_8"             android:textsize="@dimen/textsize_numeric_keys"             android:textcolor="@color/numeric_button_text_color"             android:background="@drawable/btn_register_main"             android:layout_margin="@dimen/main_buttons_margin"             android:layout_weight="1"             android:layout_gravity="center_vertical"/>      <button android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:id="@+id/btn_numeric_9"             android:text="@string/numeric_9"             android:textsize="@dimen/textsize_numeric_keys"             android:textcolor="@color/numeric_button_text_color"             android:background="@drawable/btn_register_main"             android:layout_margin="@dimen/main_buttons_margin"             android:layout_weight="1"             android:layout_gravity="center_vertical"/>   </linearlayout>  <linearlayout android:layout_width="match_parent"               android:layout_height="0dp"               android:layout_weight="1"               android:orientation="horizontal"               android:weightsum="3">       <button android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:id="@+id/btn_numeric_4"             android:text="@string/numeric_4"             android:textsize="@dimen/textsize_numeric_keys"             android:textcolor="@color/numeric_button_text_color"             android:background="@drawable/btn_register_main"             android:layout_margin="@dimen/main_buttons_margin"             android:layout_weight="1"             android:layout_gravity="center_vertical"/>      <button android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:id="@+id/btn_numeric_5"             android:text="@string/numeric_5"             android:textsize="@dimen/textsize_numeric_keys"             android:textcolor="@color/numeric_button_text_color"             android:background="@drawable/btn_register_main"             android:layout_margin="@dimen/main_buttons_margin"             android:layout_weight="1"             android:layout_gravity="center_vertical"/>      <button android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:id="@+id/btn_numeric_6"             android:text="@string/numeric_6"             android:textsize="@dimen/textsize_numeric_keys"             android:textcolor="@color/numeric_button_text_color"             android:background="@drawable/btn_register_main"             android:layout_margin="@dimen/main_buttons_margin"             android:layout_weight="1"             android:layout_gravity="center_vertical"/>  </linearlayout>  <linearlayout android:layout_width="match_parent"               android:layout_height="0dp"               android:layout_weight="1"               android:orientation="horizontal"               android:weightsum="3">       <button android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:id="@+id/btn_numeric_1"             android:text="@string/numeric_1"             android:textsize="@dimen/textsize_numeric_keys"             android:textcolor="@color/numeric_button_text_color"             android:background="@drawable/btn_register_main"             android:layout_margin="@dimen/main_buttons_margin"             android:layout_weight="1"             android:layout_gravity="center_vertical"/>      <button android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:id="@+id/btn_numeric_2"             android:text="@string/numeric_2"             android:textsize="@dimen/textsize_numeric_keys"             android:textcolor="@color/numeric_button_text_color"             android:background="@drawable/btn_register_main"             android:layout_margin="@dimen/main_buttons_margin"             android:layout_weight="1"             android:layout_gravity="center_vertical"/>      <button android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:id="@+id/btn_numeric_3"             android:text="@string/numeric_3"             android:textsize="@dimen/textsize_numeric_keys"             android:textcolor="@color/numeric_button_text_color"             android:background="@drawable/btn_register_main"             android:layout_margin="@dimen/main_buttons_margin"             android:layout_weight="1"             android:layout_gravity="center_vertical"/>  </linearlayout>  <linearlayout android:layout_width="match_parent"               android:layout_height="0dp"               android:layout_weight="1"               android:orientation="horizontal"               android:weightsum="3">       <button android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:id="@+id/btn_numeric_x"             android:text="@string/numeric_x"             android:textsize="@dimen/textsize_numeric_keys"             android:textcolor="@color/numeric_button_text_color"             android:background="@drawable/btn_register_main"             android:layout_margin="@dimen/main_buttons_margin"             android:layout_weight="1"             android:layout_gravity="center_vertical"/>      <button android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:id="@+id/btn_numeric_0"             android:text="@string/numeric_0"             android:textsize="@dimen/textsize_numeric_keys"             android:textcolor="@color/numeric_button_text_color"             android:background="@drawable/btn_register_main"             android:layout_margin="@dimen/main_buttons_margin"             android:layout_weight="1"             android:layout_gravity="center_vertical"/>      <button android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:id="@+id/btn_numeric_dot"             android:text="@string/numeric_dot"             android:textsize="@dimen/textsize_numeric_keys"             android:textcolor="@color/numeric_button_text_color"             android:background="@drawable/btn_register_main"             android:layout_margin="@dimen/main_buttons_margin"             android:layout_weight="1"             android:layout_gravity="center_vertical"/>  </linearlayout>   </linearlayout> 

Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -