0

私は、左から右の順番でいくつかの要素を含むビューを作成しようとしています。私の現在のレイアウトは次のとおりです。AndroidLineLineoutをGridLayoutのLineに合わせる

<?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:columnCount="2"> 
    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_column="0" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"> 
     <ImageView 
      android:id="@+id/Image1" 
      android:layout_height="40dp" 
      android:layout_width="40dp" 
      android:layout_marginLeft="24dp" 
      android:layout_marginTop="24dp" 
      android:layout_marginBottom="16dp" 
      android:src="@drawable/image_src" 
      android:visibility="gone" /> 
     <TextView 
      android:id="@+id/Text1" 
      android:text="SampleText" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="16dp" 
      android:layout_marginBottom="16dp" 
      android:layout_marginTop="24dp" 
      android:textSize="16sp" 
      android:gravity="center" /> 
    </LinearLayout> 
    <ImageButton 
     android:id="@+id/Button1" 
     android:layout_width="48dp" 
     android:layout_height="48dp" 
     android:layout_gravity="right" 
     android:layout_column="1" 
     android:src="@drawable/imageBtn" 
     style="?android:attr/borderlessButtonStyle" /> 
</GridLayout> 

テキストが短い場合、すべてが

When text is short - everything is ok:

OKのようです。しかし、問題は、テキストが非常に長くなることができるということです、そして、それはボタンと重なります。

Not ok image

どのように私はそれの左隅に正確に包まれたボタンが常に表示やテキストことができますか?

+0

あなたの期待される出力スクリーンショットを共有します –

+0

あなたのビューに特定のサイズを与えて、それらが重ならないようにします。あなたはあなたのXMLやコードを使ってそれを行うことができます –

+0

[GridLayoutとRow/Column Span Woe]の重複の可能性があります(http://stackoverflow.com/questions/11863329/gridlayout-and-row-column-span-woe) –

答えて

0

これは、RelativeLayoutを使用して実現できます。あなたのxmlレイアウトの下の1つをチェックしてください。

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

    <ImageButton 
     android:id="@+id/Button1" 
     style="?android:attr/borderlessButtonStyle" 
     android:layout_width="48dp" 
     android:layout_height="48dp" 
     android:layout_alignParentRight="true" 
     android:layout_marginTop="24dp" 
     android:src="@mipmap/ic_launcher" /> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_toLeftOf="@id/Button1" 
     android:orientation="horizontal"> 

     <ImageView 
      android:id="@+id/Image1" 
      android:layout_width="40dp" 
      android:layout_height="40dp" 
      android:layout_marginBottom="16dp" 
      android:layout_marginLeft="24dp" 
      android:layout_marginTop="24dp" 
      android:src="@mipmap/ic_launcher" 
      android:visibility="visible" /> 

     <TextView 
      android:id="@+id/Text1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginBottom="16dp" 
      android:layout_marginLeft="16dp" 
      android:layout_marginTop="24dp" 
      android:text="SampleText sdfsd sd sdf sdfs sdfsd fsf fsdf sd s dsfs sfs sfs sdf s fsdf sdf fsdf sdf sf sd fsdf sfsdf sfsd ffs sdf sdf sfsdf sfs sdfs sfsdfs sfs sf sfs fsfsf sf ssf " 
      android:textSize="16sp" /> 
    </LinearLayout> 
</RelativeLayout> 
+0

作業中ですが、テキストの右余白を追加する必要がありました。または、ボタンと重なってしまっていました。 –

関連する問題