0

I'm using paths as a strings in my SQLite database, and I'm using Viewbinder to adopt views to my expendablelistview ..the paths are turned images by glide library..the problem i got is there is always space after the text even if there is no string(hence no image to show) ..what sould i do to hide that space if there is no path in my sqlitedatabase( case empty or null) .

PS1: The constraint layout groups 2 imagesviews and has a specific height(100dp) ..because if there is an image and i didn't fix the height of constraint layout(for exemple if used wrap_content) i get this problem(with layout_height of imageview as wrap_content also):

https://i.stack.imgur.com/Uxm28.png (too much space around the picture)

second case: if i put the constraint layout as wrap_content and images view with a fixed layout_height(90dp) ..things looks good but the image is blurry:

https://i.stack.imgur.com/wxWtx.png

To SUM UP: the imageview should keep height as wrap_content to not look blurry and the constraint layout_height should be fixed so i don't get too much space around the picture ..so the only solution for my matter is to hide the constraint layout that group the imagesview if there is no url in both of them in mysqlite database ..thanks a lot

PS: child2 and child3= the id of imageviews in xml file

exemple Code of child2 in xmlfile:

 <android.support.constraint.ConstraintLayout
        android:id="@+id/gridview"
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:layout_below="@+id/child1"
        android:orientation="horizontal">

        <ImageView
            android:id="@+id/child2"
            android:layout_width="90dp"
            android:layout_height="wrap_content"
            android:layout_marginBottom="8dp"
            android:layout_marginLeft="8dp"
            android:layout_marginStart="8dp"
            android:layout_marginTop="8dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintVertical_bias="0.0" />

Code from activity.java:

case R.id.child2 :
    ImageView url = (ImageView) view;
    String urls;
    urls = cursor.getString(cursor.getColumnIndex(Database.DATABASE_CHILD_2));
    Glide.with(Nostrils.this).load(urls).apply(noTransformation()).into(url);
    url.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            AlertDialog.Builder mBuilder = new AlertDialog.Builder(Nostrils.this);
            View mView = getLayoutInflater().inflate(R.layout.dialog_custom_layout, null);
            PhotoView photoView = mView.findViewById(R.id.imageView);
            photoView.setImageDrawable(((ImageView)view).getDrawable());
            mBuilder.setView(mView);
            AlertDialog mDialog = mBuilder.create();
            mDialog.show();
        }
    });
    break;

Photo from the emulator

Zouhair
  • 145
  • 1
  • 2
  • 13

2 Answers2

0

If you want to hide any view you can use <view>.setVisibility();. There are three possible options here: View.VISIBLE, View.INVISIBLE, View.GONE

VISIBLE obviously makes the view visible, while INVISIBLE hides it and GONE hides it too, but also doesn't reserve the space which the view would normally take up, meaning that if a view is gone, this space you are talking about should be gone as well.

EDIT: This could be applied to your ConstraintLayout as well I think. You could do something like the following, you would just need to get a reference to your ConstraintLayout:

if(urls == null) {
    constraintLayout.setVisibility(View.GONE);
}
  • ConstraintLayout constraintLayout=(ConstraintLayout) findViewById(R.id.gridview); if(urls == null) { constraintLayout.setVisibility(View.GONE); } – Zouhair Aug 05 '18 at 15:30
  • i added that, but the app keeps crashing..and the constraintlayout didn't go – Zouhair Aug 05 '18 at 15:30
  • If the app keeps crashing, could you please share your logcat output? –  Aug 05 '18 at 17:25
  • i explained the matter here https://stackoverflow.com/questions/51695866/unable-to-set-visibility-of-constraintlayout-to-gone-if-string-is-null/51696068?noredirect=1#comment90354096_51696068 thanks for the answer – Zouhair Aug 05 '18 at 17:33
0

If i understand your question right, you should hide your PhotoView when you don't have a path. You can write something like that.

if (urls == null) {
   photoView.setVisibility(View.INVISIBLE);
}
mcarton
  • 27,633
  • 5
  • 85
  • 95
Stanislav Batura
  • 420
  • 4
  • 11
  • Please see the post ..i have edited it and explained the matter in detail..i'm trying to hide the constraintlayount that groups the imagesviews – Zouhair Aug 05 '18 at 13:01
  • I agree with Zouhair, constraintLayout.setVisibility(View.GONE); But you say, that app crash, strange i create test project and it works, maybe you have another problem, what the error you have? – Stanislav Batura Aug 05 '18 at 17:30
  • you'll find everything here .. thanks : https://stackoverflow.com/questions/51695866/unable-to-set-visibility-of-constraintlayout-to-gone-if-string-is-null/51696068?noredirect=1#comment90354096_51696068 – Zouhair Aug 05 '18 at 17:33