3
I have two Buttons on the screen, these are visible or not visible depending on the situation. There is a third situation, which should leave both visible, but does not fit on the screen. So I’d like them to be next to each other, how to do this, in code, dynamically?
Follows xml:
<RelativeLayout
android:id="@+id/relative_first"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/request_photo"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_centerHorizontal="true"
android:src="@drawable/avatar5"
android:transitionName="infoboxImage" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/request_photo"
android:layout_weight="1">
<ImageView
android:id="@+id/img_favorite"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:src="@drawable/ic_star_border_black_off_48px" />
<TextView
android:id="@+id/request_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/img_favorite"
android:padding="5dp"
android:text="Abraao Barros Lacerda"
android:textSize="25sp"
android:transitionName="infoboxName" />
<TextView
android:id="@+id/request_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/request_name"
android:layout_marginBottom="7dp"
android:padding="5dp"
android:text="[email protected]" />
<ImageView
android:id="@+id/img_points"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_alignRight="@+id/request_name" />
<TextView
android:id="@+id/txt_Points"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/request_name"
android:text="50.000 pontos" />
<HorizontalScrollView
android:id="@+id/horizontal_scroll"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/request_email"
android:layout_marginBottom="5dp">
<LinearLayout
android:id="@+id/linear_interests"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/txt_Points"
android:orientation="horizontal"></LinearLayout>
</HorizontalScrollView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/horizontal_scroll">
<android.support.v7.widget.CardView
android:id="@+id/card_1"
android:layout_width="match_parent"
android:layout_height="105dp"
android:layout_marginTop="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/textView_first"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.03"
android:padding="10dp"
android:text="Segunda-feira"
android:textSize="14sp" />
<CheckBox
android:id="@+id/button0"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.03"
android:text="Ida - 7:00" />
<CheckBox
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.03"
android:text="Volta -18:00" />
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="@+id/card_2"
android:layout_width="match_parent"
android:layout_height="105dp"
android:layout_below="@+id/card_1"
android:layout_marginTop="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/textView_second"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="10dp"
android:text="Quarta-Feira" />
<CheckBox
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Ida - 7:00" />
<CheckBox
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Volta -18:00" />
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="@+id/card_3"
android:layout_width="match_parent"
android:layout_height="105dp"
android:layout_below="@id/card_2"
android:layout_marginTop="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/check">
<TextView
android:id="@+id/textView_third"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="10dp"
android:text="Quinta-Feira" />
<CheckBox
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Ida - 7:00" />
<CheckBox
android:id="@+id/button5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Volta -18:00" />
</LinearLayout>
</android.support.v7.widget.CardView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_below="@+id/card_3"
android:id="@+id/button">
<Button
android:id="@+id/send_offer_request"
style="@style/appButtonStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_below="@+id/card_3"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:paddingTop="10dp"
android:text="Oferecer" />
<Button
android:id="@+id/send_ask_request"
style="@style/appButtonStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_below="@id/card_3"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:paddingTop="10dp"
android:text="Pedir" />
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
Follow code, the Else, should make both appear on the screen.
if (user.getProfile() == 0) {
send_offer_request.setVisibility(View.VISIBLE);
send_ask_request.setVisibility(View.INVISIBLE);
}else if(user.getProfile() == 1){
send_offer_request.setVisibility(View.VISIBLE);
send_ask_request.setVisibility(View.INVISIBLE);
}else{
send_offer_request.setVisibility(View.VISIBLE);
send_ask_request.setVisibility(View.VISIBLE);
}
They are within a Linearlayout with
orientation="horizontal"
, so they should appear side by side. Try changing , in both,android:layout_width="match_parent"
forandroid:layout_width="wrap_content"
– ramaral
@ramaral That’s what I want to do, dynamically. For they must be match_parent, unless they are side by side.
– Henrique
If you switch to wrap_content they fit on the screen?
– ramaral
@Fit ramaral, also need to space them. but fit
– Henrique