ImageButton: значок квадрата силы (высота = WRAP_CONTENT, ширина =?) - PullRequest
8 голосов
/ 24 марта 2012

В моем горизонтальном LinearLayout у меня есть TextEdit и ImageButton.ImageButton так же высоко, как TextEdit.

Я бы хотел, чтобы ImageButton был точно такой же ширины, как и его длина.

В данный момент выглядит как ширина кнопки ImageButton, когда нет масштабирования (ширина ImageButton [px] = немасштабируемая ширина рисования [px]):

example

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <EditText
        android:id="@+id/txtName"
        android:layout_width="1dp"
        android:layout_height="wrap_content"
        android:layout_weight="1" />

    <ImageButton
        android:id="@+id/btSet"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:scaleType="fitEnd"
        android:src="@drawable/pin2" />

</LinearLayout>

Как это должно выглядеть:

objective

Ответы [ 12 ]

0 голосов
/ 24 марта 2012

Просто используйте weightSum, чтобы соответственно изменить размер элементов управления ...

<?xml version="1.0" encoding="utf-8" ?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:orientation="vertical" android:layout_width="fill_parent"
      android:layout_height="fill_parent">

   <LinearLayout
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     android:orientation="horizontal"
     android:weightSum="1.0" >

   <EditText
       android:id="@+id/txtName"
       android:layout_weight="0.8"
       android:layout_height="wrap_content"
       android:layout_width="0dp" 
       android:inputType="text"
       android:singleLine="true"/>

   <ImageButton
       android:id="@+id/btSet"
       android:layout_weight="0.2"
       android:layout_height="wrap_content"
       android:layout_width="0dp"
       android:scaleType="fitEnd"
       android:src="@drawable/pin2" />

  </LinearLayout>
</LinearLayout>

Надеюсь, это поможет вам.

0 голосов
/ 24 марта 2012

Вы можете изменить размер кнопки Image, используя px ... как показано ниже ...

    `android:layout_width="5px"
    android:layout_height="5px"`
...