How to guarantee space for ImageView so that it does not shrink?

I need to create XML with the following content:
* Two TextViews with changing text (1-3 lines), one TextView below the other.
* One ImageView to the right of 2 TextViews, centered vertically, 30x30 pixels.

One of the main limitations is that it cannot occupy the entire screen when pumping in PopupWindow, which means that I cannot use the fill_parent attributes in many places.

I tried many different layouts, but TextViews repels TextViews when it is long. When the text is β€œhalf long,” the image becomes tiny but still visible. I want it to always be 30x30 pixels in size, you can wrap text and use a different line instead.

I tried to specify values ​​for width and minWidth. Also tried layout_weight = "1" for ImageView. I also tried to wrap ImageView in LinearLayout and give this parameter layout_weight = "1". Nothing works

Here is an example of what doesn't work:

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

    <LinearLayout android:layout_width="wrap_content"
       android:layout_height="wrap_content" android:orientation="vertical">

       <TextView android:id="@+id/popupTitle" android:layout_width="wrap_content"
      android:layout_height="wrap_content"/>

       <TextView android:id="@+id/popupContent"
      android:layout_width="wrap_content" android:layout_height="wrap_content"/>
    </LinearLayout>

    <ImageView android:layout_width="wrap_content"
       android:layout_height="wrap_content" android:src="@drawable/img_30x30_px" />
 </LinearLayout>
+3
source share
2 answers

, , TableView . , , , , .

, linearLayout fill_parent ( ).

, TableRow http://developer.android.com/resources/tutorials/views/hello-tablelayout.html

<TableRow>
    <!-- Column 1 -->
    <LinearLayout android:layout_width="fill_parent"
   android:layout_height="wrap_content" android:orientation="vertical">

            <TextView
                android:layout_column="1"
                android:text="Open..."
                android:padding="3dip" />
            <TextView
                android:text="Ctrl-O"
                android:gravity="right"
                android:padding="3dip" />
    </LinearLayout>
    <!-- Column 2 -->
    <ImageView android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:src="@drawable/img_30x30_px" />
</TableRow>

(, Android, ).

+3

, ! ! !:)

( ), , xml:

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:shrinkColumns="0">  

<TableRow>
<!-- Column 1 -->
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content" android:orientation="vertical">

  <TextView android:id="@+id/popupTitle"
  android:layout_width="wrap_content" android:layout_height="wrap_content"/>

  <TextView android:id="@+id/popupContent"
  android:layout_width="wrap_content" android:layout_height="wrap_content" />
  </LinearLayout>

  <!-- Column 2 -->
  <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content"
  android:layout_gravity="center_vertical" android:src="@drawable/img_30x30_px" />

</TableRow>
</TableLayout>
0

Source: https://habr.com/ru/post/1773243/


All Articles