Skip to content

Commit

Permalink
fix empty space on json editor details text
Browse files Browse the repository at this point in the history
  • Loading branch information
TrianguloY committed Feb 18, 2025
1 parent 4a9c2d2 commit 797ad6c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;

Expand All @@ -28,7 +29,7 @@ public class JsonEditorActivity extends Activity {

private JsonEditorInterface provider;
private TextView editor;
private View info;
private ViewGroup info;

// ------------------- listeners -------------------

Expand All @@ -53,6 +54,7 @@ protected void onCreate(Bundle savedInstanceState) {
}

info = findViewById(R.id.info);
AndroidUtils.limitHeight(info);
this.<TextView>findViewById(R.id.description).setText(provider.getEditorDescription());

editor = findViewById(R.id.data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import android.util.TypedValue;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

Expand Down Expand Up @@ -258,4 +260,17 @@ public void onClick(View ignored) {
text.replace(start, end, url);
return text;
}

/** Reduces the height of a view to their children's size (if less) */
static void limitHeight(ViewGroup view) {
view.post(() -> {
int childHeight = 0;
for (int i = 0; i < view.getChildCount(); i++) {
childHeight += view.getChildAt(i).getHeight();
}
if (view.getHeight() > childHeight) {
view.setLayoutParams(new LinearLayout.LayoutParams(view.getWidth(), childHeight));
}
});
}
}
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_json_editor.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:fillViewport="true">
android:fillViewport="false">

<TextView
android:id="@+id/description"
Expand Down

0 comments on commit 797ad6c

Please sign in to comment.