I am using umano sliding up panel library. I need to set panel's height to be same as a second Textview height. Example a textview.
<?xml version="1.0" encoding="utf-8"?>
<com.sothree.slidinguppanel.SlidingUpPanelLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:sothree="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:id="#+id/testtest"
android:layout_height="match_parent"
android:layout_gravity="bottom"
android:gravity="bottom"
sothree:umanoPanelHeight="65dp"
sothree:umanoShadowHeight="4dp"
>
<TextView
android:textSize="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="main"/>
<TextView
android:textSize="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="second"/>
</com.sothree.slidinguppanel.SlidingUpPanelLayout>
Is there any method which it can take textview height and send it in umano panel's heigt>?
Or if i can calculate textview text size to height in dp
Related
I've been trying to figure out how to place a container that fills the entire screen vertically inside a ScrollView that has content below.
Something like this:
[ BOX THAT FILLS ENTIRE SCREEN ]
[ Some other stuff / requires scroll to view ]
This is the content I would like below the box:
http://myupload.dk/handleupload/ce34836ostt
I've tried everything - it seems like i can't position stuff absolute to the container that fills the entire screen. I can make a box that fills the entire screen, but everything i adds below it squeezes the box together.
It works when I add a size to the box, like this:
<com.github.ksoichiro.android.observablescrollview.ObservableScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|top"
android:minWidth="25px"
android:minHeight="0px"
android:paddingTop="0dp"
android:fillViewport="true"
android:id="#+id/scroll">
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<!-- THIS BOX I WOULD LIKE TO FIT THE ENTIRE SCREEN -->
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:layout_height="100dp"
android:id="#+id/cardsPager" />
<!-- THIS CONTENT SHOULD BE BELOW THE BOX ABOVE -->
<fragment android:name="bonnier.hvadsynes.fragments.DetailsFragment"
android:id="#+id/details_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</com.github.ksoichiro.android.observablescrollview.ObservableScrollView>
Really appreciate your help!
Simon
My idea is to set the height of the screen-filling-box programmatically.
When and Where: depends on what you use e.g.in onResume there surely are better places but for now it works.
How: add an OnGlobalLayoutListener to your viewtreeobserver and then copy your scrollviews height to 'the box'.
<!--Whatever the whole things height should be, e.g. match_parent or 100dp or or or-->
<ScrollView
android:background="#0f0"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/scrollview">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- THIS BOX I WOULD LIKE TO FIT THE ENTIRE SCREEN -->
<!-- Any height works as we overwrite it anyway-->
<View
android:id="#+id/makebig"
android:background="#f00"
android:layout_width="match_parent"
android:layout_height="300dp" />
<!-- THIS CONTENT SHOULD BE BELOW THE BOX ABOVE -->
<View
android:background="#0ff"
android:id="#+id/details_fragment"
android:layout_width="match_parent"
android:layout_height="100dp"/>
</LinearLayout>
</ScrollView>
In your Activity or wherever: e.g. in onResume()
final View makebig = findViewById(R.id.makebig);
final View scrollview = findViewById(R.id.scrollview);
final ViewTreeObserver viewTreeObserver = scrollview.getViewTreeObserver();
viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
#Override
public void onGlobalLayout() {
//only do this all once
scrollview.getViewTreeObserver().removeOnGlobalLayoutListener(this);
makebig.getLayoutParams().height = scrollview.getHeight();
}
});
You can do it this way:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/layout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#A5CB3A"
android:orientation="vertical" >
</LinearLayout>
<LinearLayout
android:id="#+id/layout2"
android:layout_width="match_parent"
android:layout_height="200dp"
android:orientation="vertical" >
<!-- here goes your textview -->
</LinearLayout>
</LinearLayout>
And in the onCreate method of the Activity
Point size = new Point();
getWindowManager().getDefaultDisplay().getSize(size);
int screenHeight = size.y;
LinearLayout layout = (LinearLayout)findViewById(R.id.layout1);
ViewGroup.LayoutParams params = layout.getLayoutParams();
params.height = screenHeight; //here you can substract the height of the top bar, if your app has one
layout.setLayoutParams(params);
You are just setting the height of the screen to the inner layout.
I have a ListView displaying some text on my android activity. The problem I am facing is that some text is bigger than the other so the ListView rows don't have the same size.
I would like to have all the rows the size of the biggest. That way all the text will be display and they will all have the same size.
Here is my xml :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<CheckBox
android:id="#+id/favorite_checkbox"
android:layout_width="0dp"
android:layout_height="fill_parent"
style="?android:attr/starStyle"
android:layout_weight="1"
/>
<TextView
android:id="#+id/IdText"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="2"
/>
<TextView
android:id="#+id/StationNameText"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="2"
/>
</LinearLayout>
</LinearLayout>
Thanks for your time.
You can get the height of the 'tallest' view programmatically - How to get an Android widget's size after layout is calculated?, and then set that height to your other layouts.
I would do something like this:
DisplayMetrics displaymetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
int height = displaymetrics.heightPixels;
int width = displaymetrics.widthPixels;
int HeightOfTallestView = //method you choose from link above
IdText.setLayoutParams(new LinearLayout.LayoutParams(width, HeightOfTallestView ));
Please let me know if this works for you.
Dialog Java Code:
final Dialog dialog = new Dialog(context);
dialog.setContentView(R.layout.custom_dialog);
dialog.setTitle("Title...");
ScrollView scroll = new ScrollView(context);
scroll.setBackgroundColor(android.R.color.transparent);
scroll.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT));
// set the custom dialog components - text, image and button
TextView text = (TextView) dialog.findViewById(R.id.text);
text.setText("Android custom dialog example!");
ImageView image = (ImageView) dialog.findViewById(R.id.image);
image.setImageResource(R.drawable.icon);
dialog.show();
XML Code Here:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/layout_root"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:scrollbarAlwaysDrawVerticalTrack="true">
>
<ImageView android:id="#+id/image"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginRight="10dp"
/>
<TextView android:id="#+id/text"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:textColor="#FFF"
/>
I know that if i have only text on alert dialog it's automatically scrolling, but with an imageview automatically scrolling doesn't work.
How can i fix this problem?
Put your layout inside a ScrollView:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:id="#+id/layout_root"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:scrollbarAlwaysDrawVerticalTrack="true" >
<ImageView android:id="#+id/image"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginRight="10dp" />
<TextView android:id="#+id/text"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:textColor="#FFF" />
</LinearLayout>
<ScrollView>
I see that your LinearLayout has a horizontal orientation. So if this the case and you want to scroll horizontaly, you should replace ScrollView by HorizontalScrollView and set the orientation to horizontal.
Let me know if this works.
I would like to make an activity with this structure:
The idea is to put some text in the top, a banner allways in the top, the button OVER the banner and my canvas in the center of the view, using all the possible space.
I'm subclassing View to draw my canvas and overloading the onMeasure() method:
#Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
// Calculate the size of the board
this.squareSize = MeasureSpec.getSize(widthMeasureSpec) / BOARD_NUM_ROWS;
this.leftMargin = (MeasureSpec.getSize(widthMeasureSpec) - squareSize*BOARD_NUM_COLUMNS) / 2;
this.topMargin = this.leftMargin;
// Set the size of the board to full width and aspect ratio height
int desiredWidth = MeasureSpec.getSize(widthMeasureSpec);
int desiredHeight = this.topMargin + (BOARD_NUM_ROWS * this.squareSize) + this.topMargin;
this.setMeasuredDimension(desiredWidth, desiredHeight);
}
And this is my XML:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context=".DrawLevelActivity"
android:background="#color/activity_background">
<TextView
android:id="#+id/instructionsText"
android:gravity="center"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:paddingLeft="0dp"
android:paddingRight="0dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<com.mycanvas.BoardCanvas
android:id="#+id/boardCanvas"
android:gravity="center"
android:layout_below="#+id/instructionsText"
android:layout_centerVertical="true"
android:padding="0dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:id="#+id/solveButton"
android:gravity="center"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:paddingLeft="30dp"
android:paddingRight="30dp"
android:layout_below="#+id/boardCanvas"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<com.google.ads.AdView
xmlns:googleads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="#+id/adView"
android:gravity="center"
android:paddingTop="0dp"
android:paddingBottom="0dp"
android:paddingLeft="0dp"
android:paddingRight="0dp"
android:layout_alignParentBottom="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
googleads:adSize="BANNER"
googleads:adUnitId="#string/admob_id" />
</RelativeLayout>
Unfortunately the button appear under the banner and I think that the reason is that the canvas is very large.
The set value in onMeasure() is always smaller than MeasureSpec.getSize(heightMeasureSpec)
The key here is to use a LinearLayout setting a layout_weight value just for your canvas. This way, the top and above views will wrap their content, and the canvas will fill the free space. The layout xml would look like this.-
<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" >
<TextView
android:layout_width="match_parent"
android:layout_height="50dp"
android:gravity="center_vertical|center_horizontal"
android:background="#990099"
android:text="Some text here" />
<RelativeLayout
android:id="#+id/canvas"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#999900"
android:layout_weight="1">
<!-- The canvas -->
</RelativeLayout>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button" />
<RelativeLayout
android:id="#+id/banner"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#009999">
<!-- The banner -->
</RelativeLayout>
</LinearLayout>
Notice I set some hardcoded heights and colors so that you can easily see the results. This layout will render a view like this.-
I try to make a ScrollView to act like a ListView. So every row will be a TextView added dynamically. but the program crashes. I have a ScrollView inside a LinearLayout. What i do wrong? Thanks.
Here is my code
scroll = (ScrollView)findViewById(R.id.scrollView1);
layout = (LinearLayout) findViewById(R.id.LinearLayout1);
layout.setBackgroundColor(Color.TRANSPARENT);
TextView[] tx = new TextView[10];
for (int i = 0; i < 10; i++) {
tx[i] = new TextView(HelloWorldActivity.this);
tx[i].setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
tx[i].setText("This is the textviewNo" + i);
layout.addView(tx[i]);
}
scroll.addView(layout);
XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RelativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_horizontal"
android:orientation="vertical" >
<TextView
android:id="#+id/timeflag"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="50sp"
android:gravity="center"/>
<Button
android:id="#+id/pause"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_alignParentLeft="true"
android:layout_below="#+id/timeflag"
android:layout_marginTop="37dp"
android:text="Start" />
<LinearLayout
android:id="#+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_below="#+id/pause"
android:orientation="vertical" >
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</ScrollView>
</LinearLayout>
</RelativeLayout>
A scrollView Can only have one child. If you try to add more than 1 child to the scroll view then it will crash. You should have the LinearLayout inside of the scrollview and then dynamically add textViews to the linear layout.
You are trying to add LinearLayout1 as its own child's child (being your own grandfather, is a confusing notion).
Change you XML around like this:
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_below="#+id/pause"
>
<LinearLayout
android:id="#+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
</LinearLayout>
</ScrollView>
You cannot add views to a scrollview. You can only add them to a viewgroup, like linear or relativelayout.
It is not exactly clear what you are trying to achieve, but what is wrong with using a listview for this? You could set a max height on the listview. Or you could try wdziemia's suggestion