1

please help me, how to align the height to width. I've tried everything, it is not working. Edit: Added full layout.

enter image description here

The code to create the button looks like this

LinearLayout showLayout = (LinearLayout) view.findViewById(R.id.show_full_btn);
showButton = new ImageButton(activityContext);

<LinearLayout
                android:id="@+id/top_layout"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="0.3"
                android:orientation="horizontal">

                <LinearLayout
                    android:id="@+id/count"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="0.1"
                    android:orientation="vertical">
                </LinearLayout>

                <TextView
                    android:id="@+id/w_tv"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="0.8"
                    android:typeface="normal"/>

                <LinearLayout
                    android:id="@+id/show_full_btn"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="0.1"
                    android:scaleType="fitXY"
                    android:orientation="horizontal">
                </LinearLayout>
            </LinearLayout>

Thanks.

JDev
  • 2,157
  • 3
  • 31
  • 57

3 Answers3

0

You are giving android:scaleType to a LinearLayout which is not applicable, it works with ImageButtons, so declare your view as an ImageButton instead and apply scalyType to it, or if you kinda stuck with a layout, just make as this answer says:

Try using FrameLayout with an ImageView and LinearLayout inside. For example, try changing the alpha of the image and move it to foreground in your FrameLayout, thus the LinearLayout stays on background.

Community
  • 1
  • 1
Muhammed Refaat
  • 8,914
  • 14
  • 83
  • 118
0

If you're finding it difficult to get your results from the XML layout, then try to do it within the onCreate method of your activity. You can easily get it done.

Ruchira Randana
  • 4,021
  • 1
  • 27
  • 24
0

You are talking about an ImageButton in your question, but have not used an ImageButton in your XML, just LinearLayout. Also, in your java, the showLayout and showButton are two separate variables, and not connected.

Tim
  • 2,089
  • 1
  • 12
  • 21