Created
March 9, 2014 13:16
-
-
Save teppeihomma/9447606 to your computer and use it in GitHub Desktop.
iOS風の設定項目
This file contains 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
<?xml version="1.0" encoding="utf-8"?> | |
<shape xmlns:android="http://schemas.android.com/apk/res/android" > | |
<stroke | |
android:width="1dp" | |
android:color="@color/list_border" /> | |
<corners android:radius="10dp" /> | |
<padding | |
android:bottom="0dp" | |
android:left="0dp" | |
android:right="0dp" | |
android:top="0dp" /> | |
<solid android:color="#ffffff" /> | |
</shape> |
This file contains 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
<?xml version="1.0" encoding="utf-8"?> | |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:orientation="horizontal" | |
android:padding="10dp" > | |
<TextView | |
android:id="@+id/text" | |
android:layout_width="0dp" | |
android:layout_height="wrap_content" | |
android:layout_gravity="center_vertical" | |
android:layout_weight="1" | |
android:text="@string/dummy" | |
android:textSize="16dp" /> | |
<ImageButton | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_gravity="center_vertical" | |
android:background="@null" | |
android:contentDescription="@null" | |
android:src="@drawable/next" /> | |
</LinearLayout> |
This file contains 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
import android.content.Context; | |
import android.content.res.Resources; | |
import android.content.res.TypedArray; | |
import android.graphics.drawable.Drawable; | |
import android.util.AttributeSet; | |
import android.view.View; | |
import android.widget.LinearLayout; | |
import android.widget.TextView; | |
public class SettingListItem extends LinearLayout { | |
private String mText; | |
public SettingListItem(Context context) { | |
this(context, null); | |
} | |
public SettingListItem(Context context, AttributeSet attrs) { | |
super(context, attrs); | |
View.inflate(context, R.layout.setting_list_item, this); | |
TypedArray a = context.obtainStyledAttributes(attrs, | |
R.styleable.SettingListItem); | |
this.mText = a.getString(R.styleable.SettingListItem_text); | |
a.recycle(); | |
if (!isInEditMode()) { | |
TextView text = (TextView) findViewById(R.id.text); | |
text.setText(mText); | |
} | |
} | |
@SuppressWarnings("deprecation") | |
@Override | |
protected void onLayout(boolean changed, int l, int t, int r, int b) { | |
super.onLayout(changed, l, t, r, b); | |
LinearLayout parent = (LinearLayout) this.getParent(); | |
int count = parent.getChildCount(); | |
int position = 0; | |
int index = 0; | |
for (int i = 0; i < count; i++) { | |
View child = parent.getChildAt(i); | |
if (!(child instanceof SettingListItem)) | |
continue; | |
if (child.equals(this)) { | |
position = index; | |
} | |
index++; | |
} | |
Drawable d = null; | |
Resources res = this.getResources(); | |
if (index == 1) { | |
d = res.getDrawable(R.drawable.background_setting_list); | |
} else if (position == 0) { | |
d = res.getDrawable(R.drawable.background_setting_list_first); | |
} else if (position == index - 1 && position % 2 == 0) { | |
d = res.getDrawable(R.drawable.background_setting_list_end_even); | |
} else if (position == index - 1 && position % 2 == 1) { | |
d = res.getDrawable(R.drawable.background_setting_list_end_odd); | |
} else if (position % 2 == 0) { | |
d = res.getDrawable(R.drawable.background_setting_list_even); | |
} else { | |
d = res.getDrawable(R.drawable.background_setting_list_odd); | |
} | |
this.setBackgroundDrawable(d); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment