1

I have a main dynamically generated LinearLayout containing 4 items : - A TextView (dynamic width) - An ImageView (static width) - A TextView (dynamic width) - An ImageButton (static width)

The 3 first items should be stuck together and the last one should float on the right of the screen.

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

Current : Current screen

Expected : Expected screen

I have found a solution calculating the width of the generated items and then using that value to set the width of a layout containing the items 2 and 3 together.

Vincent Roye
  • 2,751
  • 7
  • 33
  • 53

3 Answers3

1

You can try to add a linearlayout instead of your "Gmap icon" and give him following settings

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);

and then put your button in this linearLayout

layout.addView(myImgButton);
Groco
  • 1,301
  • 15
  • 19
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>

You can set visibility of an Imageview as VISABLE/INVISABLE as per your raiting.

Dixit Panchal
  • 3,406
  • 1
  • 11
  • 14
0

You are going to use android:scaleType=""

C. Hellmann
  • 556
  • 6
  • 13