Reputation: 135
i want to have two relativelayout in first relativelayout have map and in second relativelayout i have the list..,i want on starting only layout with map will be visible on screen with a button,,when i click on button then layout with listview get open from right side with new new button on the top of it,,and prevoius button get hide.and screen get divided with two parts with different layouts..i have done some thing but from starting onward m getting half half screen.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/ListView_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="1" >
<RelativeLayout
android:id="@+id/rl_ListView1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5" >
<Button
android:id="@+id/getdirection"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Get Directions" />
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.MapFragment" >
</fragment>
</RelativeLayout>
<RelativeLayout
android:id="@+id/rl_ListView2"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:visibility="invisible" >
<Button
android:id="@+id/hide"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Get Directions" />
<ListView
android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:visibility="invisible" />
</RelativeLayout>
</LinearLayout>
MainActivity
show = (TextView)findViewById(R.id.getdirection);
show1 = (TextView)findViewById(R.id.hide);
rt = (RelativeLayout)findViewById(R.id.rl_ListView2);
show.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(rt.getVisibility()==View.INVISIBLE)
{
rt.setVisibility(View.VISIBLE);
}
show.setVisibility(View.INVISIBLE);
}
});
show1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(rt.getVisibility()==View.VISIBLE)
{
rt.setVisibility(View.INVISIBLE);
}
show1.setVisibility(View.INVISIBLE);
}
});
Upvotes: 3
Views: 25309
Reputation: 36
From my view you did not set the orientation in the LinearLayout
to be vertical for the two RelativeLayouts. I also suggests you put the map and Button
in a FrameLayout
as well instead of RelativeLayout
.
Upvotes: 0
Reputation: 307
You can try with isShown()
as suggested by Amiya
<b>
button2.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view) {
if(button1.isShown()) {
// Your_Staff
}
else{
// Your_Staff
}
}
});
</b>
Upvotes: 0
Reputation: 28823
Try this:
You are getting layout1 in half screen from starting due to weight property. You can try not giving weight in starting and give it programatically on button click.
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
button1.setVisibility(View.GONE); //hide old button
layout2.setVisibility(View.VISIBLE); //show layout2
//set Relativelayout 1 to half screen
RelativaLayout.LayoutParams params = layout1.getLayoutParams();
params.weight = 0.5;
layout1.setLayoutParams(params);
}
});
Hope this helps.
Upvotes: 4
Reputation: 1649
button.setOnClickListener(this);
public void onClick(View v) {
layoutid.setVisibility(View.GONE);
}
Upvotes: 0