-1

イメージの左側にイメージがあり、イメージのすぐ隣に2行のテキストがある単純なグリッドビューがあります。画像の「ROWSPANは、」2行のテキストの完全な高さを使用するためには、2:GridViewでイメージを自動スケールする

<?xml version="1.0" encoding="utf-8"?> 
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:rowCount="2" 
    android:columnCount="2"> 

<ImageView 
    android:id="@+id/imageView" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_column="0" 
    android:layout_row="0" 
    android:layout_rowSpan="2" 
    android:src="@drawable/disconnected" /> 

<TextView 
    android:id="@+id/connectionText" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:ems="10" 
    android:layout_column="1" 
    android:layout_row="0" 
    android:layout_rowSpan="1" 
    android:inputType="textPersonName" 
    android:text="Name" /> 

<TextView 
    android:id="@+id/stateText" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:ems="10" 
    android:layout_column="1" 
    android:layout_row="1" 
    android:layout_rowSpan="1" 
    android:inputType="textPersonName" 
    android:text="disconnected" /> 
</GridLayout> 

私の問題:私は高さに収まるサイズに画像の自動縮尺したいと思います2行のテキストのうち、それが固有の高さで表示されるのではなく、レイアウトに自動的にそれをさせる方法はありますか?

ありがとうございます!

答えて

3
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:rowCount="2" 
     android:columnCount="2"> 

    <ImageView 
     android:id="@+id/imageView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_column="0" 
     android:layout_row="0" 
     android:scaleType="fitCenter" 
     android:layout_rowSpan="2" 
     android:src="@drawable/disconnected" /> 

    <TextView 
     android:id="@+id/connectionText" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:ems="10" 
     android:layout_column="1" 
     android:layout_row="0" 
     android:layout_rowSpan="1" 
     android:inputType="textPersonName" 
     android:text="Name" /> 

    <TextView 
     android:id="@+id/stateText" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:ems="10" 
     android:layout_column="1" 
     android:layout_row="1" 
     android:layout_rowSpan="1" 
     android:inputType="textPersonName" 
     android:text="disconnected" /> 
</GridLayout> 

私はxmlを変更しました。これは役に立ちます。 私は特定の幅と高さの値を与え、スケールの種類を中央に合わせるように設定しました。あなたがプログラミングすることにより、動的高さを設定することができます

、このコードは

 int first_view_hight = firstView.getLineHeight(); 


     int second_view_height = secondView.getLineHeight(); 


     int totalHeight = first_view_hight + second_view_height; 


     GridLayout.LayoutParams lp = (GridLayout.LayoutParams) setHeightImage.getLayoutParams(); 
     lp.height = totalHeight; 
     lp.width = totalHeight; 
     imageView.setLayoutParams(lp); 
+0

フムのに役立ちますが、これは右横に2行のテキストの実際の大きさに動的に40×40のDPの固定サイズにスケーリングしませんそれ!? – Elmi

+0

私はそれがあなたを助けるかもしれない私の答えを更新しました – RajatN

関連する問題