Tenho dois buttons na tela, estes ficam ou não visíveis dependendo da situação. Há uma terceira situação, que deveria deixar os dois visíveis, mas não cabe na tela. Então, gostaria que eles passassem a ficar um ao lado do outro, como fazer isso, no código, dinamicamente?
Segue 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>
Segue código, o else, deve fazer com que os dois apareçam na tela.
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);
}
orientation="horizontal"
, por isso deveriam aparecer lado a lado. Experimente mudar , nos dois,android:layout_width="match_parent"
paraandroid:layout_width="wrap_content"