Skip to content

Instantly share code, notes, and snippets.

@writtmeyer
writtmeyer / align_to_center.xml
Created August 27, 2016 08:04
Align one view's edge to another view's center in Android's ConstraintLayout
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/target"
android:layout_width="wrap_content"
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container_delivery_item"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
@writtmeyer
writtmeyer / GsonBuilderForRenamingWitoutUsingGsonAnnotations
Last active February 16, 2019 22:24
If you want to keep your domain objects free from GSON annotations, this is a possible way to do this.
Gson gson = new GsonBuilder()
.registerTypeAdapter(Date.class, new DateTypeAdapter())
.setFieldNamingStrategy(new FieldNamingStrategy() {
@Override
public String translateName(Field f) {
if (f.getName().equals("stars")) {
return "stargazers_count";
} else if (f.getName().equals("repositories")) {
return "items";
} else {
@writtmeyer
writtmeyer / ItemListActivity.java
Last active May 25, 2017 23:22
A very quick test case for up navigation in master detail views. I simply enhanced some of the code, the wizard creates. This is more or less the code of my blogpost "Adding ActionBarSherlock to Your Project" (http://www.grokkingandroid.com/adding-actionbarsherlock-to-your-project/). Lines 73 and 74 add an animation and line 76 adds the detail f…
package com.example.test;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.util.Log;
import android.view.MenuItem;