Getting padding in fullscreen camera view (FrameLayout) - android

I have this layout:
`
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:orientation="vertical"
android:padding="0dp"
android:background="#android:color/transparent"
android:id="#+id/parent_view"
>
<FrameLayout
android:id="#+id/camera_preview"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<Button
android:id="#+id/button_capture"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="50dp"
android:text="Capture" />
</FrameLayout>
</LinearLayout>
`
I am getting black padding in camera view like this, on the right side, notice the vertical black space/strip on right:
Don't mind the capture button in middle of screen, I'll position it later. But the question I have is, how to remove the unwanted padding and make FramLayout full screen?

CameraSourcePreview doesn't fill whole screen height that bug fixed by
Comment or remove below lines from CameraSourcePreview.java
if (childHeight > layoutHeight) {
childHeight = layoutHeight;
childWidth = (int)(((float) layoutHeight / (float) height) * width);
}

Related

MaterialCalendarView not occupying full width android

I am placing a Material calendar view and i want the calendar height to occupy half of the screen and it was made by using layout weight but the calendar not occupying the full width.
one more problem is that I want to increase the text size of the date please refer me any idea
The XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="symphony.acube.com.symphony.activity.patient.acitivity.mySchedule.MyScheduleActivity">
<include layout="#layout/toolbar_layout"></include>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/llCalendarContainer"
android:orientation="vertical"
android:layout_weight="1">
<com.prolificinteractive.materialcalendarview.MaterialCalendarView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/calendarView"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:mcv_showOtherDates="all"
app:mcv_selectionColor="#color/toolbar_red"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
</LinearLayout>
</LinearLayout>
</LinearLayout>
The following is the actual window i am getting currently
In the above calendar should occupy full width and also the text size of the date must be some big
Thankyou in advance
To stretch the width of the calendar should:
The measureTileSize reduce by a factor of (in the method onMeasure class MaterialCalendarView)
int childHeightMeasureSpec = MeasureSpec.makeMeasureSpec ((int) (p.height * (measureTileSize / 1.5)), MeasureSpec.EXACTLY);
The same is done in the MonthView
int childHeightMeasureSpec = MeasureSpec.makeMeasureSpec ((int) (measureTileSize / 1.5), MeasureSpec.EXACTLY);
Something come up with the background (stretched into an oval)
For more follow this issue

dynamically increase and decrease the relative layout

dynamically increase and decrease the relative layout , i want to shrink the size of relative layout when recycler view popup from bottom of screen and after using it agian the screen will return into normal size(in recycler view im sung icons to put on relative view)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_weight="1">
////////tool bar
<include layout="#layout/toolbar" />
<RelativeLayout
android:id="#+id/rel1"
android:layout_width="wrap_content"
android:layout_height="400dp"
android:layout_below="#+id/toolbar"
android:layout_weight="1">
<com.cmlibrary.CircleMenu
android:id="#+id/circle_menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="180dp"
android:layout_marginTop="180dp"
/>
</RelativeLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_below="#+id/rel1"
android:padding="5dp" />
</RelativeLayout>
Better way is to show and hide the visibility of views as required. But if you want to increase and decrease the size then below code will help you.
private void layoutParams() {
RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) relativeLayout.getLayoutParams();
ViewGroup.LayoutParams params = recyclerView.getLayoutParams();
/* When recyclerView shows*/
layoutParams.height = layoutParams.height - params.height;
relativeLayout.setLayoutParams(layoutParams);
/* When recyclerView hidden*/
layoutParams.height = RelativeLayout.LayoutParams.MATCH_PARENT;
relativeLayout.setLayoutParams(layoutParams);
}
Hope this will help.

How to center text in android screen (not center in parent)

I want to center a small text in center of screen based on the default "Empty activity" as per code samples in Android Studio 2.1.
The layout xml file i use today is as provided below. I inflate it in the OnCreate method as normal through the setContentView, so the layout as defined in the xml dont fill the whole screen. Thus the layout_centerInParent will center my texts in the parent, but not center in screen. How do i get my text to center on screen, while keeping my action bar?
Illustration of problem
Centering in parent leads to "bad" position. Centering on screen would give "good" postion.
main_activity.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/main_root"
android:layout_width="match_parent"
android:layout_height="match_parent"
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.sara.internetcheck.MainActivity">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true">
<TextView
android:id="#+id/text_header"
style="#style/TextAppearance.AppCompat.Headline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:gravity="center"
android:text="#string/good_news_title" />
<TextView
android:id="#+id/text_body"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/text_header"
android:text="#string/good_news_text" />
</RelativeLayout>
</RelativeLayout>
Use for example CoordinatorLayout. Elements in this layout has no relation between them so can be one on another.
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:id="#+id/root_layout"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="?attr/actionBarSize"
android:text="Text not in center">
</TextView>
</RelativeLayout>
<!-- This is centered TextView -->
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="?attr/actionBarSize"
android:text="Text in center"
>
</TextView>
</android.support.design.widget.CoordinatorLayout>
Two important things:
Centered TextView should be children of CoordinatorLayout
To center in CoordinatorLayout use attribute android:layout_gravity="center"
If we want exacly center we need to change margin because toolbar size is our not wanted difference for exactly center, i used android:layout_marginBottom="?attr/actionBarSize" to move TextView up by toolbar height.
Calculating screen and setting position programically is not good proposition, this can cause not wanted problems when for example user rotates screen.
You can get the real dimension of you screen by
DisplayMetrics displayMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
displayMetrics.widthPixels; //screen width
displayMetrics.heightPixels; //screen height
then
LayoutParams layoutParams = new LayoutParams(int width, int height);
layoutParams.setMargins(int left, int top, int right, int bottom);
viewToCenter.setLayoutParams(layoutParams);

full screen layout in Scroll View

I want to have 2 layouts inside ScrollView. First layout should be on the full screen and second layout below first one. When activity starts it is not possible see second layout. Second layout is possible see after scroll screen. Please take a look on my image for better understand.
Layout code: `
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="15dp" >
<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:orientation="vertical" >
</LinearLayout>
<LinearLayout
android:id="#+id/layout2"
android:layout_width="match_parent"
android:layout_height="200dp"
android:orientation="vertical" >
<!-- this layout can be any height you want -->
</LinearLayout>
</LinearLayout>
</ScrollView>`
Get the device screen height:
Point size = new Point();
getWindowManager().getDefaultDisplay().getSize(size);
int screenHeight = size.y;
Find the LinearLayout:
LinearLayout layout = (LinearLayout)findViewById(R.id.layout1);
Set the height of the layout based on the screen height you got earlier:
LayoutParams params = layout.getLayoutParams();
params.height = screenHeight - getStatusBarHeight();
Done. Be sure to call all of those methods in your onCreate method.
Hope this helps!

How to split the screen dynamically in android without xml

I have tried to split the screen using xml..here is the code
Please try this xml..I need the same layout programatically.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="318dp"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal"
android:background="#android:color/holo_purple">
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="318dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal" android:background="#android:color/holo_purple">
</LinearLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="318dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal"
android:background="#android:color/holo_blue_dark">
</LinearLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="318dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal"
android:background="#android:color/darker_gray">
</LinearLayout>
</LinearLayout>
</LinearLayout>
But, I need to do programatically to split the screen. Can anyone provide me the solution?
By splitting the screen you mean dividing layouts width then you can try as below..
// gets the screen width
float screenWidth = getWindowManager()
.getDefaultDisplay().getWidth();
You will get screen width from above code..
and for screen height
// gets the screen height
float screenHeight = getWindowManager()
.getDefaultDisplay().getHeight();
then all you have to do is set the layout width using LayoutParams.
LinearLayout view = (LinearLayout) findViewById(R.id.ur_layout_id);
view.setLayoutParams(new LinearLayout.LayoutParams((int) screenWidth / 3,
(int) screenHeight , 1f));
you can set layoutwidth to divide screen in half by screenWidth / 2, in 3 parts by screenWidth / 3 and so on..
Hope this helps..

Categories

Resources