IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Android Discussion :

Définir taille image


Sujet :

Android

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Profil pro
    Inscrit en
    Janvier 2007
    Messages
    83
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2007
    Messages : 83
    Par défaut Définir taille image
    Bonjour à tous,
    Dans le menu drawer d'une application, j'ai en plus du titre de la section un picto. Pour le moment, j'ai mis directement via illustrator le picto à la dimension finale, ce qui a pour effet de "pixeliser et flouter" le rendu. Je souhaite donc conserver l'image en plus grand dans le dossier des drawables et réduire sa dimension quand je l’appelle (comme dans beaucoup de langages en fait (genre <img src="foobar.png" width="X" height="X" alt=""> ).
    Je ne sais pas trop où et comment faire ça.

    Dans la partie "navigation Items" ?
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    public class NavigationItem {
        private String mText;
        private Drawable mDrawable;
     
        public NavigationItem(String text, Drawable drawable) {
            mText = text;
            mDrawable = drawable;
     
        }
     
        public String getText() {
            return mText;
        }
     
        public void setText(String text) {
            mText = text;
        }
     
        public Drawable getDrawable() {
            return mDrawable;
        }
     
        public void setDrawable(Drawable drawable) {
            mDrawable = drawable;
        }
     
    }
    Ou dans la partie "liste" ?
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
        @Override
        public void onNavigationDrawerItemSelected(int position) {
            selectItem(position);
        }
     
        public List<NavigationItem> getMenu() {
            List<NavigationItem> items = new ArrayList<NavigationItem>();
            items.add(new NavigationItem("1", getResources().getDrawable(R.drawable.1)));
            items.add(new NavigationItem("2", getResources().getDrawable(R.drawable.2)));
            return items;
        }
    Merci par avance.

  2. #2
    Membre expérimenté Avatar de Altak
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Octobre 2014
    Messages
    170
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Octobre 2014
    Messages : 170
    Par défaut
    Bonjour,

    Tu peux directement mettre cette fonctionnalité dans ton layout d'affichage avec les attributs adjustViewBounds et scaleType.
    Ces deux attribut vont te permettre de 1) garder le même ratio d'image (ton image ne sera pas déformer) 2) de la redimensionner pour qu'elle rentre dans la zone que tu lui a assigné.

    Voici un exemple:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
     
                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="100dp"
                    android:adjustViewBounds="true"
                    android:scaleType="centerInside"
                    android:src="@drawable/picto" />
    Ton picto va faire 100dp de hauteur et va redimensionné pour que le ratio soit toujours le même.

    GLHF

  3. #3
    Membre confirmé
    Profil pro
    Inscrit en
    Janvier 2007
    Messages
    83
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2007
    Messages : 83
    Par défaut
    Bonjour,
    Le problème est que je n'ai pas d'image views définie dans le xml.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    <RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_height="match_parent"
        android:layout_width="match_parent"
        android:id="@+id/googleDrawer"
        android:background="@android:color/white">
     
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="168dp"
            android:background="@drawable/fond"
            android:id="@+id/navigationHeader"
            android:paddingTop="24dp">
     
        </RelativeLayout>
     
        <View
            android:layout_width="match_parent"
            android:background="#1f000000"
            android:layout_height="1dp"
            android:id="@+id/separator"
            android:layout_below="@+id/navigationHeader"
            android:layout_marginBottom="8dp" />
     
        <android.support.v7.widget.RecyclerView
            android:id="@+id/drawerList"
            android:layout_width="match_parent"
            android:clickable="true"
            android:scrollbars="vertical"
            android:layout_height="161dp"
            android:background="@color/myDrawerBackground"
            android:layout_below="@+id/separator"
            android:layout_gravity="center_vertical"
            android:layout_alignParentBottom="true" />
     
    </RelativeLayout>

  4. #4
    Membre expérimenté Avatar de Altak
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Octobre 2014
    Messages
    170
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Octobre 2014
    Messages : 170
    Par défaut
    Bonjour,

    Dans tes morceaux de code, je vois que tu ajoute des NavigationItem (dans ton RecyclerView je suppose?) mais je ne vois pas a quel moment tu affiche le drawable qui est contenu dedans.
    Si tu pouvais nous montrer ta classe complète, cela nous serais utiles je pense (ou montre nous comment tu affiche ton drawable en tout cas).

    GL HF

  5. #5
    Membre confirmé
    Profil pro
    Inscrit en
    Janvier 2007
    Messages
    83
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2007
    Messages : 83
    Par défaut
    Voici le code au complet :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    public class NavigationDrawerFragment extends Fragment implements NavigationDrawerCallbacks {
     
        /**
         * Remember the position of the selected item.
         */
        private static final String STATE_SELECTED_POSITION = "selected_navigation_drawer_position";
     
        /**
         * Per the design guidelines, you should show the drawer on launch until the user manually
         * expands it. This shared preference tracks this.
         */
        private static final String PREF_USER_LEARNED_DRAWER = "navigation_drawer_learned";
     
        /**
         * A pointer to the current callbacks instance (the Activity).
         */
        private NavigationDrawerCallbacks mCallbacks;
     
        /**
         * Helper component that ties the action bar to the navigation drawer.
         */
        private ActionBarDrawerToggle mActionBarDrawerToggle;
     
        private DrawerLayout mDrawerLayout;
        private RecyclerView mDrawerList;
        private View mFragmentContainerView;
     
        private int mCurrentSelectedPosition = 0;
        private boolean mFromSavedInstanceState;
        private boolean mUserLearnedDrawer;
     
     
     
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
     
            // Read in the flag indicating whether or not the user has demonstrated awareness of the
            // drawer. See PREF_USER_LEARNED_DRAWER for details.
            SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity());
            mUserLearnedDrawer = sp.getBoolean(PREF_USER_LEARNED_DRAWER, false);
     
            if (savedInstanceState != null) {
                mCurrentSelectedPosition = savedInstanceState.getInt(STATE_SELECTED_POSITION);
                mFromSavedInstanceState = true;
            }
        }
     
        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                 Bundle savedInstanceState) {
            View view = inflater.inflate(R.layout.fragment_navigation_drawer, container, false);
            mDrawerList = (RecyclerView) view.findViewById(R.id.drawerList);
            LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
            layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
            mDrawerList.setLayoutManager(layoutManager);
            mDrawerList.setHasFixedSize(true);
     
            final List<NavigationItem> navigationItems = getMenu();
            NavigationDrawerAdapter adapter = new NavigationDrawerAdapter(navigationItems);
            adapter.setNavigationDrawerCallbacks(this);
            mDrawerList.setAdapter(adapter);
            selectItem(mCurrentSelectedPosition);
            return view;
        }
     
        public boolean isDrawerOpen() {
            return mDrawerLayout != null && mDrawerLayout.isDrawerOpen(mFragmentContainerView);
        }
     
        public ActionBarDrawerToggle getActionBarDrawerToggle() {
            return mActionBarDrawerToggle;
        }
     
        public DrawerLayout getDrawerLayout() {
            return mDrawerLayout;
        }
     
     
        @Override
        public void onNavigationDrawerItemSelected(int position) {
            selectItem(position);
        }
     
     
        public List<NavigationItem> getMenu() {
            List<NavigationItem> items = new ArrayList<NavigationItem>();
            items.add(new NavigationItem("1", getResources().getDrawable(R.drawable.1)));
            items.add(new NavigationItem("2", getResources().getDrawable(R.drawable.2)));
            return items;
        }
     
        public void setup(int fragmentId, DrawerLayout drawerLayout, Toolbar toolbar) {
            mFragmentContainerView = getActivity().findViewById(fragmentId);
            mDrawerLayout = drawerLayout;
     
            mDrawerLayout.setStatusBarBackgroundColor(getResources().getColor(R.color.myPrimaryDarkColor));
     
            mActionBarDrawerToggle = new ActionBarDrawerToggle(getActivity(), mDrawerLayout, toolbar, R.string.drawer_open, R.string.drawer_close) {
                @Override
                public void onDrawerClosed(View drawerView) {
                    super.onDrawerClosed(drawerView);
                    if (!isAdded()) return;
     
                    getActivity().invalidateOptionsMenu(); // calls onPrepareOptionsMenu()
                }
     
                @Override
                public void onDrawerOpened(View drawerView) {
                    super.onDrawerOpened(drawerView);
                    if (!isAdded()) return;
                    if (!mUserLearnedDrawer) {
                        mUserLearnedDrawer = true;
                        SharedPreferences sp = PreferenceManager
                                .getDefaultSharedPreferences(getActivity());
                        sp.edit().putBoolean(PREF_USER_LEARNED_DRAWER, true).apply();
                    }
                    getActivity().invalidateOptionsMenu(); // calls onPrepareOptionsMenu()
                }
            };
     
            // If the user hasn't 'learned' about the drawer, open it to introduce them to the drawer,
            // per the navigation drawer design guidelines.
            if (!mUserLearnedDrawer && !mFromSavedInstanceState) {
                mDrawerLayout.openDrawer(mFragmentContainerView);
            }
     
            // Defer code dependent on restoration of previous instance state.
            mDrawerLayout.post(new Runnable() {
                @Override
                public void run() {
                    mActionBarDrawerToggle.syncState();
                }
            });
     
            mDrawerLayout.setDrawerListener(mActionBarDrawerToggle);
        }
     
        private void selectItem(int position) {
            mCurrentSelectedPosition = position;
            if (mDrawerLayout != null) {
                mDrawerLayout.closeDrawer(mFragmentContainerView);
            }
            if (mCallbacks != null) {
                mCallbacks.onNavigationDrawerItemSelected(position);
            }
            ((NavigationDrawerAdapter) mDrawerList.getAdapter()).selectPosition(position);
        }
     
        public void openDrawer() {
            mDrawerLayout.openDrawer(mFragmentContainerView);
        }
     
        public void closeDrawer() {
            mDrawerLayout.closeDrawer(mFragmentContainerView);
        }
     
        @Override
        public void onAttach(Activity activity) {
            super.onAttach(activity);
            try {
                mCallbacks = (NavigationDrawerCallbacks) activity;
            } catch (ClassCastException e) {
                throw new ClassCastException("Activity must implement NavigationDrawerCallbacks.");
            }
        }
     
        @Override
        public void onDetach() {
            super.onDetach();
            mCallbacks = null;
        }
     
        @Override
        public void onSaveInstanceState(Bundle outState) {
            super.onSaveInstanceState(outState);
            outState.putInt(STATE_SELECTED_POSITION, mCurrentSelectedPosition);
        }
     
        @Override
        public void onConfigurationChanged(Configuration newConfig) {
            super.onConfigurationChanged(newConfig);
            // Forward the new configuration the drawer toggle component.
            mActionBarDrawerToggle.onConfigurationChanged(newConfig);
        }
     
        public View getGoogleDrawer() {
            return mFragmentContainerView.findViewById(R.id.googleDrawer);
        }
     
        public static class RoundImage extends Drawable {
            private final Bitmap mBitmap;
            private final Paint mPaint;
            private final RectF mRectF;
            private final int mBitmapWidth;
            private final int mBitmapHeight;
     
            public RoundImage(Bitmap bitmap) {
                mBitmap = bitmap;
                mRectF = new RectF();
                mPaint = new Paint();
                mPaint.setAntiAlias(true);
                mPaint.setDither(true);
                final BitmapShader shader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
                mPaint.setShader(shader);
     
                mBitmapWidth = mBitmap.getWidth();
                mBitmapHeight = mBitmap.getHeight();
            }
     
            @Override
            public void draw(Canvas canvas) {
                canvas.drawOval(mRectF, mPaint);
            }
     
            @Override
            protected void onBoundsChange(Rect bounds) {
                super.onBoundsChange(bounds);
                mRectF.set(bounds);
            }
     
            @Override
            public void setAlpha(int alpha) {
                if (mPaint.getAlpha() != alpha) {
                    mPaint.setAlpha(alpha);
                    invalidateSelf();
                }
            }
     
            @Override
            public void setColorFilter(ColorFilter cf) {
                mPaint.setColorFilter(cf);
            }
     
            @Override
            public int getOpacity() {
                return PixelFormat.TRANSLUCENT;
            }
     
            @Override
            public int getIntrinsicWidth() {
                return mBitmapWidth;
            }
     
            @Override
            public int getIntrinsicHeight() {
                return mBitmapHeight;
            }
     
            public void setAntiAlias(boolean aa) {
                mPaint.setAntiAlias(aa);
                invalidateSelf();
            }
     
            @Override
            public void setFilterBitmap(boolean filter) {
                mPaint.setFilterBitmap(filter);
                invalidateSelf();
            }
     
            @Override
            public void setDither(boolean dither) {
                mPaint.setDither(dither);
                invalidateSelf();
            }
        }
    }
    Merci de te pencher sur ma demande

  6. #6
    Membre expérimenté Avatar de Altak
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Octobre 2014
    Messages
    170
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Octobre 2014
    Messages : 170
    Par défaut
    Re,

    On peut avoir le code complet de ton NavigationDrawerAdapter s'il te plait?

    GL HF

Discussions similaires

  1. [ImageMagick] Contenu d'un répertoire et taille images
    Par FoxLeRenard dans le forum Bibliothèques et frameworks
    Réponses: 8
    Dernier message: 07/02/2006, 17h40
  2. [FLASH 5] Définir taille
    Par ouldfella dans le forum Flash
    Réponses: 4
    Dernier message: 04/01/2006, 11h52
  3. taille page = taille image
    Par sohnic dans le forum Balisage (X)HTML et validation W3C
    Réponses: 2
    Dernier message: 25/12/2005, 13h47
  4. Taille image d'accueil
    Par JeanMi66 dans le forum Balisage (X)HTML et validation W3C
    Réponses: 8
    Dernier message: 19/09/2005, 11h27
  5. [Image]Vérifier taille image lors d'upload FTP
    Par MiJack dans le forum Bibliothèques et frameworks
    Réponses: 5
    Dernier message: 10/09/2004, 01h10

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo