android69
شنبه 09 اسفند 1393, 10:59 صبح
سلام کسی از دوستان میدونه چطوری میشه این ویو رو ساخت؟یه نمونه مثالی داره؟ کادرقرمز رو منظورمه فایل ضمیمه شده
atpf67
شنبه 09 اسفند 1393, 12:10 عصر
سلام بزرگوار
من این ویو رو کاملش توی جاوا نوشتم با یه سری قابلیت ها که البته فقط ویو رو در اختیارتون قرار میدم، بقیه ش دیگه با خودتون.
فایل جاوا:
import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener ;
import android.view.animation.ScaleAnimation;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
import android.widget.ProgressBar;
import android.widget.TextView;
/**
*
* @author Abolhassan (mehandev member)
*
*/
public class UpdateNotifyView extends FrameLayout {
private static FrameLayout frameIcon, frameAlarm;
private static ImageView icon;
private static ProgressBar progressBar;
private LayoutParams layoutParams;
private View viewAlarm;
private TextView textAlarm;
private int getDensity(Context context){
DisplayMetrics metrics = new DisplayMetrics();
((Activity)context).getWindowManager().getDefaultD isplay().getMetrics(metrics);
return metrics.densityDpi;
}
public UpdateNotifyView(Context context, AttributeSet attrs) {
super(context, attrs);
if(isInEditMode())
createView(context);
else
init(context);
}
public UpdateNotifyView(Context context) {
super(context);
if(!isInEditMode())
init(context);
}
public UpdateNotifyView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
if(!isInEditMode())
init(context);
}
private void init(Context context){
createView(context);
}
private void createView(Context context){
this.layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
this.layoutParams.gravity = Gravity.CENTER_VERTICAL|Gravity.CENTER_HORIZONTAL;
UpdateNotifyView.frameIcon = new FrameLayout(context);
UpdateNotifyView.frameIcon.setLayoutParams(this.la youtParams);
this.layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParam s.WRAP_CONTENT);
this.layoutParams.gravity = Gravity.CENTER_VERTICAL|Gravity.CENTER_HORIZONTAL;
UpdateNotifyView.icon = new ImageView(context);
UpdateNotifyView.icon.setScaleType(ScaleType.CENTE R);
UpdateNotifyView.icon.setImageResource(R.drawable. update_view_icon);// عکس اون دوتا فلش دایره ای رو بده بجای بکگروند
UpdateNotifyView.icon.setLayoutParams(this.layoutP arams);
UpdateNotifyView.progressBar = new ProgressBar(context);
UpdateNotifyView.progressBar.setVisibility(GONE);
UpdateNotifyView.progressBar.setLayoutParams(this. layoutParams);
if(isInEditMode()){
this.layoutParams = new LayoutParams(40, 40);
}else{
if(getDensity(context)== DisplayMetrics.DENSITY_LOW){
this.layoutParams = new LayoutParams(40, 40);
}else if(getDensity(context)== DisplayMetrics.DENSITY_XXHIGH
||getDensity(context)== DisplayMetrics.DENSITY_XXXHIGH){
this.layoutParams = new LayoutParams(60, 60);
}else {
this.layoutParams = new LayoutParams(43, 50);
}
}
UpdateNotifyView.frameAlarm = new FrameLayout(context);
UpdateNotifyView.frameAlarm.setPadding(2, 8, 0, 0);
UpdateNotifyView.frameAlarm.setLayoutParams(this.l ayoutParams);
if(isInEditMode()){
this.layoutParams = new LayoutParams(15, 15);
}else{
switch(getDensity(context)){
case DisplayMetrics.DENSITY_LOW:
this.layoutParams = new LayoutParams(15, 15);
break;
case DisplayMetrics.DENSITY_MEDIUM:
this.layoutParams = new LayoutParams(20, 20);
break;
case DisplayMetrics.DENSITY_HIGH:
this.layoutParams = new LayoutParams(30, 30);
break;
case DisplayMetrics.DENSITY_XHIGH:
this.layoutParams = new LayoutParams(40, 40);
break;
case DisplayMetrics.DENSITY_XXHIGH:
this.layoutParams = new LayoutParams(40, 50);
break;
case DisplayMetrics.DENSITY_XXXHIGH:
this.layoutParams = new LayoutParams(40, 40);
break;
}
}
this.viewAlarm = new View(context);
this.viewAlarm.setBackgroundResource(R.drawable.up date_view_alarm_bg);
this.viewAlarm.setLayoutParams(this.layoutParams);
this.layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
this.layoutParams.gravity = Gravity.CENTER;
this.textAlarm = new TextView(context);
this.textAlarm.setText("!");
if(isInEditMode()){
this.textAlarm.setPadding(6, 0, 0, 0);
}else{
switch(Screen.getDensity(context)){
case DisplayMetrics.DENSITY_LOW:
this.textAlarm.setPadding(6, 0, 0, 0);
break;
case DisplayMetrics.DENSITY_MEDIUM:
this.textAlarm.setPadding(8, 0, 0, 0);
break;
case DisplayMetrics.DENSITY_HIGH:
this.textAlarm.setPadding(13, 0, 0, 0);
break;
case DisplayMetrics.DENSITY_XHIGH:
this.textAlarm.setPadding(17, 0, 0, 0);
break;
case DisplayMetrics.DENSITY_XXHIGH:
this.textAlarm.setPadding(17, 0, 0, 0);
break;
case DisplayMetrics.DENSITY_XXXHIGH:
this.textAlarm.setPadding(17, 0, 0, 0);
break;
}
}
this.textAlarm.setTextColor(Color.WHITE);
this.textAlarm.setTextSize(TypedValue.COMPLEX_UNIT _SP, 15);
UpdateNotifyView.frameIcon.addView(UpdateNotifyVie w.icon);
UpdateNotifyView.frameIcon.addView(UpdateNotifyVie w.progressBar);
UpdateNotifyView.frameAlarm.addView(this.viewAlarm );
UpdateNotifyView.frameAlarm.addView(this.textAlarm );
this.addView(UpdateNotifyView.frameIcon);
this.addView(UpdateNotifyView.frameAlarm);
}
}
فایل drawable مورد نیاز: اسم فایل رو بذارید update_view_alarm_bg.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval" >
<gradient android:startColor="#ff0000"
android:centerColor="#ff0000"
android:endColor="#96ff0000"/>
</shape>
hamedg1366
شنبه 09 اسفند 1393, 12:11 عصر
یه Linear از نوع Horizintal که داخلش یه TextView همراه با یه Button
+
GriadView
atpf67
شنبه 09 اسفند 1393, 12:15 عصر
یه Linear از نوع Horizintal که داخلش یه TextView همراه با یه Button
+
GriadView
بزرگوار اگه اشتباه نکنم اینجوری اون قسمت قرمزه نمیاد روی باتن باید از FrameLayout استفاده کنن.
android69
شنبه 09 اسفند 1393, 13:06 عصر
بزرگوار اگه اشتباه نکنم اینجوری اون قسمت قرمزه نمیاد روی باتن باید از FrameLayout استفاده کنن.
من اون خط قزمزه رو نمیخوام
فقط میخوام اون قسمتی که رنگی ده رو بسازم
atpf67
شنبه 09 اسفند 1393, 13:28 عصر
من اون خط قزمزه رو نمیخوام
فقط میخوام اون قسمتی که رنگی ده رو بسازم
آخ... ببخشید من پس اشتباه یه چیز دیگه رو دادم بهتون.
من این قسمت رو دادم به شما.:لبخند:
128953
همون جواب دوستمون درسته.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.tst.MainActivity" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
<TextView
android:id="@+id/textView1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="right|center_vertical"
android:layout_weight="1"
android:gravity="right"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<GridView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#acbdaa" >
</GridView>
</LinearLayout>
vBulletin® v4.2.5, Copyright ©2000-1404, Jelsoft Enterprises Ltd.