Created
April 1, 2015 06:32
-
-
Save ishan1608/eae0cd6690e0938a1c44 to your computer and use it in GitHub Desktop.
Content Toggler like Gmail
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.... | |
.... | |
<!-- Container for the heading and content --> | |
<LinearLayout | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:orientation="vertical"> | |
<!-- Heading container. Can contain multiple views inside it. --> | |
<LinearLayout | |
android:id="@+id/headingContainer" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:orientation="horizontal" | |
android:background="#ffffc828"> | |
<TextView | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="Heading"/> | |
<ImageView | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:src="@drawable/aeroplane"/> | |
</LinearLayout> | |
<!-- Container for the togglable. Contains multiple views inside it. Default Visibility: gone --> | |
<LinearLayout | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:orientation="vertical" | |
android:background="#ffff9809" | |
android:visibility="gone"> | |
<TextView | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="Content"/> | |
<ImageView | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:src="@drawable/holiday"/> | |
</LinearLayout> | |
</LinearLayout> | |
</LinearLayout> | |
.... | |
.... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.... | |
.... | |
public class MainActivity extends Activity { | |
.... | |
.... | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
.... | |
.... | |
// Setting toggler on the right drawer's contents | |
View headingView = findViewById(R.id.headingContainer); | |
headingView.setOnClickListener(new contentToggler()); | |
} | |
} | |
class contentToggler implements View.OnClickListener { | |
@Override | |
public void onClick(View v) { | |
ViewGroup parent = (ViewGroup) v.getParent(); | |
View childView = parent.getChildAt(parent.indexOfChild(v) + 1); | |
this.viewToggler(childView); | |
} | |
private void viewToggler(View view) { | |
if(view.getVisibility() == View.VISIBLE) { | |
view.setVisibility(View.GONE); | |
} else { | |
view.setVisibility(View.VISIBLE); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment