2016-04-05 9 views
0

動的に作成されたレイアウトに入れのImageButtonの重力変更する方法: - TextView(動的width) - ImageView(静的width) - TextViewを (width動的) - ImageButton(静的widthアンドロイド:私が主動的に生成<code>LinearLayout</code>含む4つの項目を有する

3つの最初の項目が貼り合わせされるべきであり、最後のものは、画面の右側に浮くはずです。

Name - Rating starts - Number of reviews................. Gmap icon 

電流:期待 Current screen

Expected screen

ソリューションは、生成されたアイテムの幅を計算して、アイテムを含むlayoutの幅を設定し、その値を使用して、私を発見しました2と3を一緒にします。

+0

現在のスクリーンショットと予想されるものを投稿してください。 –

答えて

0

あなたは以下の設定

LinearLayout layout = new LinearLayout(this); 
layout.setOrientation(LinearLayout.HORIZONTAL); 

layout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT)); 
layout.setGravity(Gravity.RIGHT); 

の代わりに "GMAPアイコン" ののLinearLayoutを追加し、彼に与えることをしようとし、こののLinearLayout

layout.addView(myImgButton); 
0
<LinearLayout 
android:layout_width="match_parent" 
android:layout_height="50sp" 
android:orientation="horizontal" 
android:weightSum="3" 
> 
<TextView 
    android:layout_width="0sp" 
    android:layout_height="50sp" 
    android:layout_weight="0.5" 
    android:text="Bussiness 1" 
    android:gravity="center" 
    android:background="#000" 
    android:textColor="#FF0000" 
    android:textSize="18sp" 
    /> 
<LinearLayout 
    android:layout_width="0sp" 
    android:layout_height="50sp" 
    android:layout_weight="0.7" 
    android:background="#0000FF" 
    > 
    <ImageView 
     android:layout_width="20sp" 
     android:layout_height="20sp" 
     android:layout_gravity="center|center_horizontal" 
     android:layout_margin="3sp" 
     android:src="@drawable/star" 
     /> 
    <ImageView 
     android:layout_width="20sp" 
     android:layout_height="20sp" 
     android:layout_gravity="center|center_horizontal" 
     android:layout_margin="3sp" 
     android:src="@drawable/star" 
     /> 
    <ImageView 
     android:layout_width="20sp" 
     android:layout_height="20sp" 
     android:layout_gravity="center|center_horizontal" 
     android:layout_margin="3sp" 
     android:src="@drawable/star" 
     /> 
    <ImageView 
     android:layout_width="20sp" 
     android:layout_height="20sp" 
     android:layout_gravity="center|center_horizontal" 
     android:layout_margin="3sp" 
     android:src="@drawable/star" 
     /> 
    <ImageView 
     android:layout_width="20sp" 
     android:layout_height="20sp" 
     android:layout_gravity="center|center_horizontal" 
     android:layout_margin="5sp" 
     android:src="@drawable/star" 
     /> 
</LinearLayout> 
<LinearLayout 
    android:layout_width="0sp" 
    android:layout_height="50sp" 
    android:layout_weight="1.8" 
    android:background="#FF0000" 

    android:gravity="right" 
    > 
<ImageView 
    android:layout_width="25sp" 
    android:layout_height="25sp" 
    android:layout_gravity="center" 
    android:src="@drawable/profile" 
    android:layout_marginRight="10sp" 
    /> 
</LinearLayout> 

であなたのボタンを置くことができます

イメージビューの可視性をVISABLE/INVISABLEとして設定することができます。

+0

私は問題のあるビューを扱っています。 –

関連する問題