下面列出了android.widget.FrameLayout#setForegroundGravity ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public CellHolder(LayoutInflater inflater) {
fl = (FrameLayout) inflater.inflate(
R.layout.list_item_top_grid_item, null);
iv = (ImageView) fl.findViewById(R.id.iv);
ivAnimated = (ImageView) fl
.findViewById(R.id.iv_animated);
flContainer = (FrameLayout) fl.findViewById(R.id.fl);
Drawable foreground = inflater.getContext().getResources()
.getDrawable(R.drawable.grid_photo_overlay);
foreground.getPadding(paddingRect);
fl.setForeground(foreground);
fl.setPadding(paddingRect.left, paddingRect.top, paddingRect.right,
paddingRect.bottom);
fl.setForegroundGravity(Gravity.FILL);
}
@Override
public View style(View view, JSONObject attributes) throws Exception {
super.style(view, attributes);
FrameLayout frameLayout = (FrameLayout) view;
if(attributes.has("measureAllChildren")) {
frameLayout.setMeasureAllChildren(attributes.getBoolean("measureAllChildren"));
}
if(attributes.has("foregroundGravity")) {
String gravity = attributes.getString("foregroundGravity");
if(gravity.equalsIgnoreCase("start")) {
frameLayout.setForegroundGravity(Gravity.START);
}else if(gravity.equalsIgnoreCase("top")) {
frameLayout.setForegroundGravity(Gravity.TOP);
}else if(gravity.equalsIgnoreCase("end")) {
frameLayout.setForegroundGravity(Gravity.END);
}else if(gravity.equalsIgnoreCase("bottom")) {
frameLayout.setForegroundGravity(Gravity.BOTTOM);
}else if(gravity.equalsIgnoreCase("center")) {
frameLayout.setForegroundGravity(Gravity.CENTER);
}else if(gravity.equalsIgnoreCase("center_horizontal")) {
frameLayout.setForegroundGravity(Gravity.CENTER_HORIZONTAL);
}else if(gravity.equalsIgnoreCase("center_vertical")) {
frameLayout.setForegroundGravity(Gravity.CENTER_VERTICAL);
}
}
return frameLayout;
}
private View createIndeterminateProgressView(View convertView,
ViewGroup parent)
{
if (convertView == null)
{
FrameLayout container = new FrameLayout(context);
container.setForegroundGravity(Gravity.CENTER);
ProgressBar progress = new ProgressBar(context);
container.addView(progress);
convertView = container;
}
return convertView;
}
private View createIndeterminateProgressView(View convertView,
ViewGroup parent)
{
if (convertView == null)
{
FrameLayout container = new FrameLayout(context);
container.setForegroundGravity(Gravity.CENTER);
ProgressBar progress = new ProgressBar(context);
container.addView(progress);
convertView = container;
}
return convertView;
}
private View createIndeterminateProgressView(View convertView, ViewGroup parent) {
if (convertView == null) {
FrameLayout container = new FrameLayout(context);
container.setForegroundGravity(Gravity.CENTER);
ProgressBar progress = new ProgressBar(context);
container.addView(progress);
convertView = container;
}
return convertView;
}
private View createIndeterminateProgressView(View convertView, ViewGroup parent) {
if (convertView == null) {
FrameLayout container = new FrameLayout(context);
container.setForegroundGravity(Gravity.CENTER);
ProgressBar progress = new ProgressBar(context);
container.addView(progress);
convertView = container;
}
return convertView;
}
private View createIndeterminateProgressView(View convertView,
ViewGroup parent) {
if (convertView == null) {
FrameLayout container = new FrameLayout(context);
container.setForegroundGravity(Gravity.CENTER);
ProgressBar progress = new ProgressBar(context);
container.addView(progress);
convertView = container;
}
return convertView;
}
static View createIndeterminateProgressView(View convertView,
ViewGroup parent) {
if (convertView == null) {
Context context = parent.getContext();
FrameLayout container = new FrameLayout(context);
container.setForegroundGravity(Gravity.CENTER);
ProgressBar progress = new ProgressBar(context);
container.addView(progress);
convertView = container;
}
return convertView;
}
@SuppressWarnings("deprecation")
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
convertView = mViews[position];
if(convertView == null){
AnimatedScaleDrawable drawable = new AnimatedScaleDrawable(
parent.getContext().getResources().getDrawable(R.drawable.heart));
drawable.setInterpolator(new BounceInterpolator());
drawable.setInvertTransformation(true);
drawable.setDuration(500);
FrameLayout frame = (FrameLayout)LayoutInflater.from(parent.getContext())
.inflate(R.layout.item_frame, parent, false);
if(position == 0){
// ProgressBar example
ProgressBar progress = (ProgressBar)LayoutInflater.from(parent.getContext())
.inflate(R.layout.item_progress, frame, false);
progress.setIndeterminateDrawable(drawable);
frame.addView(progress);
}
else{
if(position == 1 || position == 2){
// Background drawable example
frame.setBackgroundDrawable(drawable);
if(position == 2){
drawable.setUseBounds(false);
}
}else{
// Foreground's with Gravity example
frame.setForeground(drawable);
frame.setForegroundGravity(mGravity[position - 3]);
}
// no need to call drawable.start() for ProgressBar widgets
drawable.start();
}
TextView textView = (TextView)frame.findViewById(R.id.text);
textView.setText(String.format("#%02d %s", position, mNames[position]));
convertView = frame;
}
return convertView;
}