buttons on frame layout - android

Hi I am developing an android video app. I have buttons on my frame layout. I need the buttons a little big. But they are getting shrinked as I get the preview on the screen.
Video.xml looks as below
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<FrameLayout
android:id="#+id/videoview"
android:layout_width="720px"
android:layout_height="480px" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ImageView
android:id="#+id/mybutton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:paddingLeft="2dp"
android:paddingRight="2dp"
android:src="#drawable/record_video" />
<RadioGroup
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<RadioButton
android:id="#+id/flashoff"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="OFF"
android:textSize="8dp" />
<RadioButton
android:id="#+id/flashtorch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Torch"
android:textSize="8dp" />
</RadioGroup>
</LinearLayout>
</LinearLayout>
and the oncreate is as below
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.videocapture);
DisplayMetrics metrics = this.getResources().getDisplayMetrics();
vwidth = metrics.widthPixels;
vheight = metrics.heightPixels;
Log.e("vwidth"," "+vwidth);
Log.e("vheight"," "+vheight);
//Get Camera for preview
myCamera = getCameraInstance();
if(myCamera == null)
{
Toast.makeText(VideoCapture.this,"Fail to get Camera",Toast.LENGTH_LONG).show();
}
myCameraSurfaceView = new MyCameraSurfaceView(this, myCamera);
final FrameLayout myCameraPreview = (FrameLayout)findViewById(R.id.videoview);
myCameraPreview.addView(myCameraSurfaceView);
myCameraPreview.post(new Runnable()
{
#Override
public void run()
{
int width = vwidth;
int height = vheight;
LayoutParams lp = myCameraPreview.getLayoutParams();
lp.height = height;
lp.width = width - 80;
myCameraPreview.setLayoutParams(lp);
}
});
recVideo = (ImageView)findViewById(R.id.mybutton);
recVideo.setOnClickListener(myButtonOnClickListener);
flashOff = (RadioButton)findViewById(R.id.flashoff);
flashTorch = (RadioButton)findViewById(R.id.flashtorch);
}
How do I resolve this. Please Help. Thanks

Try to use this layout , you can change weight according to your requirement.Please change background colors .Hope it will help.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<FrameLayout
android:id="#+id/videoview"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3"
android:background="#FFCCCC" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#99FF66"
android:orientation="vertical" >
<ImageView
android:id="#+id/mybutton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="2dp"
android:paddingRight="2dp"
android:src="#drawable/ic_launcher" />
<RadioGroup
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<RadioButton
android:id="#+id/flashoff"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="OFF"
android:textSize="8dp" />
<RadioButton
android:id="#+id/flashtorch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Torch"
android:textSize="8dp" />
</RadioGroup>
</LinearLayout>
</LinearLayout>

Related

Show/Hide top bar like chrome, but with some static content and a listview

First let me give a short introduction and then show you what end goal looks:
So far I've added a scrolllistener to my listactivity, so that I can detect scrolling, though it does not give me any animation on android:animateLayoutChanges="true". So when i change the margin's of the view programmatically, it just does these changes instantly, and not that well, any help is most welcomed.
As you can see in my xml, i place the item I'm going to hide slowly first so other will be above it on the Z-axis.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:lector="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:animateLayoutChanges="true"
android:background="#color/background_greyish">
<LinearLayout
android:id="#+id/disappearingHeaderLabel"
android:layout_width="fill_parent"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_marginTop="60dp"
android:animateLayoutChanges="true"
android:layout_height="50dp"
android:background="#color/solid_white"
android:orientation="horizontal"
android:weightSum="7">
<TextView
android:id="#+id/ProductDetailLabel"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="5dip"
android:layout_marginLeft="15dp"
android:layout_marginRight="5dp"
android:layout_marginTop="10dip"
android:layout_weight="4"
android:singleLine="true"
android:text="PRODUKTER"
android:textColor="#color/solid_red"
android:textSize="20dp" />
<Button
android:id="#+id/priceChooserButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="15dp"
android:layout_marginTop="10dp"
android:layout_weight="3"
android:background="#drawable/buttonbackground"
android:clickable="true"
android:singleLine="true"
android:text="#string/retailprice"
android:textColor="#android:color/white"
android:textSize="15dp"
android:textStyle="bold" />
</LinearLayout>
<dk.myapp.mobile.views.PageHeaderView
android:id="#+id/header"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"></dk.myapp.mobile.views.PageHeaderView>
<LinearLayout
android:id="#+id/expandingListContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:animateLayoutChanges="true"
android:layout_alignParentLeft="true"
android:layout_marginTop="110dp"
android:layout_above="#+id/paginationBarContainer"
android:orientation="vertical">
<LinearLayout
android:id="#+id/headerLabel"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:background="#color/transparent"
android:orientation="horizontal"
android:weightSum="11">
<LinearLayout
android:layout_width="0dp"
android:layout_weight="3"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/sortAmountLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:singleLine="false"
android:text="1354"
android:textColor="#color/solid_red"
android:textSize="15dp" />
<TextView
android:id="#+id/sortLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dip"
android:text="Produkter"
android:singleLine="true"
android:textColor="#color/solid_red"
android:textSize="15dp" />
</LinearLayout>
<Button
android:id="#+id/filterBtn"
android:layout_width="0dp"
android:layout_height="35dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="15dp"
android:layout_marginTop="10dp"
android:layout_weight="4"
android:background="#drawable/button_background_red"
android:clickable="true"
android:singleLine="true"
android:text="#string/retailprice"
android:textColor="#color/solid_white"
android:textSize="15dp"
android:textStyle="bold" />
<Spinner
android:id="#+id/sortSpinner"
android:layout_width="0dp"
android:layout_weight="4"
android:layout_height="35dp"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:background="#drawable/spinner_background"
android:drawSelectorOnTop="true"
android:focusable="false"
android:focusableInTouchMode="false"
android:prompt="#string/sort" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="1dip"
android:background="#color/divider_color"></LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<ListView
android:id="#+id/android:list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:divider="#color/divider_color"
android:dividerHeight="1dip"
android:paddingLeft="15dip"
android:scrollbarStyle="outsideInset"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp" />
</LinearLayout>
</LinearLayout>
#Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
int marginRemoved = firstVisibleItem * 30;
if (marginRemoved > 110) {
marginRemoved = 110;
}
if (previousMarginRemoved != marginRemoved) {
previousMarginRemoved = marginRemoved;
LinearLayout disappearingHeaderContainer = (LinearLayout) findViewById(R.id.disappearingHeaderLabel);
RelativeLayout.LayoutParams disappearingHeaderContainerLayoutParams = (RelativeLayout.LayoutParams) disappearingHeaderContainer.getLayoutParams();
LinearLayout expandingListViewContainer = (LinearLayout) findViewById(R.id.expandingListContainer);
RelativeLayout.LayoutParams expandingListViewContainerParams = (RelativeLayout.LayoutParams) expandingListViewContainer.getLayoutParams();
if (disappearingHeaderStartMargin == -1 && expandingHeaderStartMargin == -1) {
disappearingHeaderStartMargin = disappearingHeaderContainerLayoutParams.topMargin;
expandingHeaderStartMargin = expandingListViewContainerParams.topMargin;
}
float disappearingHeaderTopMarginFloat = disappearingHeaderStartMargin - (marginRemoved * pixelDensity);
int disappearingHeaderTopMargin = Math.round(disappearingHeaderTopMarginFloat);
if (marginRemoved > 50) {
marginRemoved = 50;
}
float expandingContainerTopMarginFloat = expandingHeaderStartMargin - (marginRemoved * pixelDensity);
int expandingContainerTopMargin = Math.round(expandingContainerTopMarginFloat);
disappearingHeaderContainerLayoutParams.setMargins(disappearingHeaderContainerLayoutParams.leftMargin,
disappearingHeaderTopMargin,
disappearingHeaderContainerLayoutParams.rightMargin,
disappearingHeaderContainerLayoutParams.bottomMargin);
expandingListViewContainerParams.setMargins(expandingListViewContainerParams.leftMargin,
expandingContainerTopMargin,
expandingListViewContainerParams.rightMargin,
expandingListViewContainerParams.bottomMargin);
if ((lastChangeDate < System.currentTimeMillis()-100)) {
lastChangeDate = System.currentTimeMillis();
disappearingHeaderContainer.setLayoutParams(disappearingHeaderContainerLayoutParams);
expandingListViewContainer.setLayoutParams(expandingListViewContainerParams);
}
}
}
};

Slide In View Animation

I want a relative layout to slide into a screen.
At the moment I set the layout to be below a layout that takes up the whole screen
<FrameLayout
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:animateLayoutChanges="true"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/ghostIv"
android:src="#drawable/results_ghost"
android:visibility="gone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"/>
<ImageView
android:id="#+id/ghostShadowIv"
android:visibility="gone"
android:src="#drawable/results_ghost_shadow"
android:layout_centerHorizontal="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/ghostIv"/>
<TextView
android:id="#+id/noFilterTv"
android:textStyle="bold"
android:gravity="center_horizontal"
android:textColor="#color/LightTextGrey"
android:visibility="gone"
android:text="#string/no_filters"
android:paddingLeft="50dp"
android:paddingRight="50dp"
android:layout_centerHorizontal="true"
android:layout_below="#+id/ghostShadowIv"
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>
<com.allryder.android.ui.views.ScheduleView
android:visibility="invisible"
android:background="#color/White"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/scheduleView"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"/>
<View
android:id="#+id/shadowV"
android:visibility="gone"
android:layout_above="#+id/ratingRl"
android:layout_height="4dp"
android:layout_width="match_parent"
android:background="#drawable/bottom_shadow"/>
<RelativeLayout
android:id="#+id/ratingRl"
android:layout_below="#+id/scheduleView"
android:background="#color/White"
android:clickable="true"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:background="#drawable/time_view_selector"
android:padding="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="#+id/ratePromptTv"
android:layout_toLeftOf="#+id/closeRatingIv"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:gravity="center|left"
android:text="#string/rate_prompt"/>
<ImageView
android:background="#drawable/time_view_selector"
android:padding="10dp"
android:clickable="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/ratePromptTv"
android:layout_alignBottom="#+id/ratePromptTv"
android:id="#+id/closeRatingIv"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:src="#drawable/search_clear"/>
</RelativeLayout>
</RelativeLayout>
</FrameLayout>
<fragment android:id="#+id/filters_drawer"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="end"
android:name="com.allryder.android.ui.fragments.FiltersDrawerFragment"/>
Then make this call
ratingRl.animate().translationY(- ratingRl.getHeight());
But it doesn't slide into the screen. If the view is in the screen to start off with, the view does animate. What is the problem?
ratingRl.animate().translationY(- ratingRl.getHeight()).setDuration(300).start();
I have done similar task in my recent project.
background = (RelativeLayout) findViewById(R.id.slidingBackground);
positionOffScreen(background);
private void positionOffScreen(View v){
View myView = v;
int amountOffscreen = (int)(getScreenWidth());
boolean offscreen = true;
int xOffset = (offscreen) ? amountOffscreen : 0;
RelativeLayout.LayoutParams rlParams = (RelativeLayout.LayoutParams)myView.getLayoutParams();
rlParams.setMargins(-1*xOffset, 0, xOffset, 0);
myView.setLayoutParams(rlParams);
}
protected float getScreenWidth() {
DisplayMetrics displaymetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
return (float) displaymetrics.widthPixels;
}
When you want to start animation call this method
private void startAnimation(int duration){
TranslateAnimation a = new TranslateAnimation(Animation.ABSOLUTE,0,Animation.ABSOLUTE,getScreenWidth(),Animation.ABSOLUTE,0,Animation.ABSOLUTE,0);
a.setDuration(duration);
a.setFillAfter(false);
background.startAnimation(a);
}
When you want to interrupt animation
background.clearAnimation();
Here is layout example. The sliding view has to be placed on RelativeLayout.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/background" >
<RelativeLayout
android:id="#+id/slidingBackground"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#64000000"
android:orientation="vertical" >
</RelativeLayout>
...
And this is the app link where I use this sliding view.

Android Video not fitting the width in portrait of the videoview and not occupying full screen in landscape

Android video not fitting the width of the videoview when in portrait, how can i make the width of my video fit the width of my videoview when in portrait, and when i change orientation of the screen to landscape i would like the video to fill the whole screen like the youtube app does. when in portrait the video is to start from the top to the middle of the screen and and when in landscape to fill the whole screen. here is what i have tried, i have also add links of the complete screenshot
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:weightSum="100" >
<VideoView
android:id="#+id/videoview"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_gravity="center"
android:layout_weight="53" >
</VideoView>
<LinearLayout
android:id="#+id/linearLayout"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="7"
android:background="#drawable/top_bar"
android:orientation="horizontal" >
<LinearLayout
android:id="#+id/settings"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
android:paddingBottom="5dp"
android:paddingTop="5dp" >
<ImageView
android:id="#+id/set"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="#string/desc"
android:src="#drawable/settings" />
</LinearLayout>
<LinearLayout
android:id="#+id/low_tab"
android:layout_width="70dp"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
android:paddingBottom="5dp"
android:paddingTop="5dp" >
<ImageView
android:id="#+id/low"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="#string/desc"
android:src="#drawable/low" />
</LinearLayout>
<LinearLayout
android:id="#+id/high_tab"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
android:paddingBottom="5dp"
android:paddingTop="5dp" >
<ImageView
android:id="#+id/high"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="#string/desc"
android:src="#drawable/high" />
</LinearLayout>
<LinearLayout
android:id="#+id/audio_tab"
android:layout_width="70dp"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
android:paddingBottom="5dp"
android:paddingTop="5dp" >
<ImageView
android:id="#+id/audio"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="#string/desc"
android:src="#drawable/audio" />
</LinearLayout>
<LinearLayout
android:id="#+id/full_screen"
android:layout_width="30dp"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
android:paddingBottom="5dp"
android:paddingTop="5dp" >
<ImageView
android:id="#+id/full"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="#string/desc"
android:src="#drawable/full" />
</LinearLayout>
<LinearLayout
android:id="#+id/fresh"
android:layout_width="30dp"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
android:paddingBottom="5dp"
android:paddingTop="5dp" >
<ImageView
android:id="#+id/refresh"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="#string/desc"
android:src="#drawable/refresh" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="7"
android:background="#drawable/comment_bar"
android:orientation="horizontal" >
<LinearLayout
android:id="#+id/liveblog_tab"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:background="#drawable/select"
android:gravity="center"
android:orientation="vertical"
android:paddingBottom="5dp"
android:paddingTop="5dp" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="#string/desc"
android:src="#drawable/live_blog" />
</LinearLayout>
<LinearLayout
android:id="#+id/addcom_tab"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:background="#drawable/select"
android:gravity="center"
android:orientation="vertical"
android:paddingBottom="5dp"
android:paddingLeft="15dp"
android:paddingTop="5dp" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="#string/desc"
android:src="#drawable/add_comment" />
</LinearLayout>
</LinearLayout>
<FrameLayout
android:id="#+id/frame"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="33" >
<LinearLayout
android:id="#+id/liveblog"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<WebView
android:id="#+id/browser"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</WebView>
</LinearLayout>
<LinearLayout
android:id="#+id/comments"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
</LinearLayout>
</FrameLayout>
</LinearLayout>
You need to have two different layouts. One for the portrait and the one for the landscape.
Create two xml files with the same name and put them into folders "layout-land" for landscape and "layout-port" for portrait.
And Here you can take a look how to handle orientation changes.
This can be the layout to make video view full screen.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<VideoView android:id="#+id/myvideoview"
android:layout_width="fill_parent"
android:layout_alignParentRight="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:layout_height="fill_parent">
</VideoView>
</RelativeLayout>
EDIT : This is How you can handle it in the method.
#Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
// Checks the orientation of the screen
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
Toast.makeText(this, "landscape", Toast.LENGTH_SHORT).show();
setContentView(Your Landscape layout);
} else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
Toast.makeText(this, "portrait", Toast.LENGTH_SHORT).show();
setContentView(Your portrait layout);
}
}
For linearlayout I'm not sure. But using relativelayout you can do this as below.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<VideoView
android:id="#+id/videoview"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true" >
</VideoView>
//your other xml content
....
....
....
</RelativeLayout>
And If you want the videoview to be filled in height too. then you need to do this code:
<VideoView
android:id="#+id/videoview"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true">
</VideoView>
//your other xml content
....
....
....
</RelativeLayout>
Let me know if it's helped. Thanks.
private void fitStretchClick() {
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
retriever.setDataSource(this, Uri.parse(arrayListVideos.get(mPosition).getSongPath()));
Bitmap bmp = retriever.getFrameAtTime();
float width = ((float) bmp.getWidth()) / ((float) bmp.getHeight());
int width2 = getWindowManager().getDefaultDisplay().getWidth();
int height = getWindowManager().getDefaultDisplay().getHeight();
float f = (float) width2;
float f2 = (float) height;
float f3 = f / f2;
ViewGroup.LayoutParams layoutParams = mVideoView.getLayoutParams();
ViewGroup.LayoutParams layoutParams2 = mVideoView.getLayoutParams();
if (changedNow) {
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mVideoView.getLayoutParams();
params.width = metrics.widthPixels;
params.height = metrics.heightPixels;
params.leftMargin = 0;
mVideoView.setLayoutParams(params);
Toast.makeText(this, "Stretch To Screen", Toast.LENGTH_SHORT).show();
changedNow = false;
return;
} else {
changedNow = true;
Toast.makeText(this, "Fit To Screen", Toast.LENGTH_SHORT).show();
if (width > f3) {
layoutParams.width = width2;
layoutParams.height = (int) (f / width);
mVideoView.setLayoutParams(layoutParams);
return;
}
layoutParams.width = (int) (width * f2);
layoutParams.height = height;
mVideoView.setLayoutParams(layoutParams);
}
}

how to create expendable layout on each node

im creating and application which have thre nodes (Description, Contents, Nutrition) like this image http://imgur.com/TmJT6GI when user click any node it will expend and show another screen inside it how i will do that? i will see there is expendable listview available but its show single list on each node like this example http://ranfeng0610.blog.163.com/blog/static/1857082842011727111359969/ is expend listview in each node i lie to expend layout on reach node al node show difrent layout User interface) how i willl make screenlike this? help me please u have any idea????
1、main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<!-- 禁用系统自带图标android:groupIndicator="#null" -->
<ExpandableListView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:groupIndicator="#null"
android:id="#+id/mExpandableListView"
/>
</LinearLayout>
2、group.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation = "horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:layout_width = "25dip"
android:layout_height = "25dip"
android:layout_marginTop="10dip"
android:id="#+id/mImageView"
/>
<TextView
android:id = "#+id/group_tv"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:paddingLeft = "30px"
android:paddingBottom = "10px"
android:textSize = "26sp"/>
</LinearLayout>
3、child.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation = "horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_gravity = "center_vertical"
android:id = "#+id/child_iv"
android:layout_width = "70px"
android:layout_height = "70px"
android:paddingLeft = "30px"
android:paddingTop = "2px"
android:paddingBottom = "5px"
android:src = "#drawable/icon"/>
<TextView
android:layout_gravity = "center_vertical"
android:id = "#+id/child_tv"
android:layout_width = "fill_parent"
android:layout_height = "fill_parent"
android:paddingLeft = "30px"
android:paddingTop = "10px"
android:paddingBottom = "5px"
android:textSize = "30sp"/>
</LinearLayout>
u can make it without using expandable list-view..u have to just control visibility of your views.
MainActivity
boolean flag;
boolean flag2;
LinearLayout llContains;
LinearLayout llContents;
LinearLayout llContains2;
LinearLayout llContents2;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
llContains = (LinearLayout)findViewById(R.id.llContains);
llContents = (LinearLayout)findViewById(R.id.llContents);
llContains2 = (LinearLayout)findViewById(R.id.llContains2);
llContents2 = (LinearLayout)findViewById(R.id.llContents2);
llContains.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v)
{
if(!flag)
{
llContents.setVisibility(View.VISIBLE);
flag = true;
}
else
{
llContents.setVisibility(View.GONE);
flag = false;
}
}
});
llContains2.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v)
{
if(!flag2)
{
llContents2.setVisibility(View.VISIBLE);
flag2 = true;
}
else
{
llContents2.setVisibility(View.GONE);
flag2 = false;
}
}
});
}
activity_main.xml
<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"
>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<LinearLayout
android:id="#+id/llContains"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="3dp"
android:background="#000000"
>
</LinearLayout>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Contains"
android:textSize="20dp"
android:layout_marginLeft="10dp"
android:padding="10dp"
/>
<LinearLayout
android:id="#+id/llContents"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="4"
android:padding="10dp"
android:visibility="gone"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1"
android:gravity="center"
>
<ImageView
android:src="#drawable/ic_launcher"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
/>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Cheese"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1"
android:gravity="center"
>
<ImageView
android:src="#drawable/ic_launcher"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="1"/>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Tomatos"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1"
android:gravity="center"
>
<ImageView
android:src="#drawable/ic_launcher"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="1"/>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Wheat"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1"
android:gravity="center"
>
<ImageView
android:src="#drawable/ic_launcher"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="1"/>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Salt"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/llContains2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="3dp"
android:background="#000000"
>
</LinearLayout>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Contains2"
android:textSize="20dp"
android:layout_marginLeft="10dp"
android:padding="10dp"
/>
<LinearLayout
android:id="#+id/llContents2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="4"
android:padding="10dp"
android:visibility="gone"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1"
android:gravity="center"
>
<ImageView
android:src="#drawable/ic_launcher"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
/>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Cheese"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1"
android:gravity="center"
>
<ImageView
android:src="#drawable/ic_launcher"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="1"/>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Tomatos"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1"
android:gravity="center"
>
<ImageView
android:src="#drawable/ic_launcher"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="1"/>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Wheat"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1"
android:gravity="center"
>
<ImageView
android:src="#drawable/ic_launcher"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="1"/>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Salt"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
if it helps then let me know.

how can i put the framelayout in the bottom of the application?

i want to put a framelayout in the bottom by doing this :
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="#color/darkblue"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Bottom"
android:textSize="30px"
android:textColor="#color/white"
android:layout_gravity="center"
/>
</FrameLayout>
But it doesn't work . It's staying in the middle of my application.
This is the whole thing :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/white"
>
<FrameLayout
android:id="#+id/first"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#color/darkblue"
>
<ImageView
android:id="#+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:src="#drawable/back4"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Title"
android:textSize="30px"
android:textColor="#color/white"
android:layout_gravity="center"
/>
</FrameLayout>
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#color/white"
android:id="#+id/second"
android:layout_below="#id/first"
>
<ImageView
android:id="#+id/banner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/chuck"
/>
</FrameLayout>
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#color/white"
android:id="#+id/third"
android:layout_below="#id/second"
>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:id="#+id/sum"
android:text="Summary "
android:textSize="25px"
android:textColor="#color/black"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<ImageView
android:id="#+id/s_btn"
android:src="#drawable/next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/sum"
android:layout_alignTop="#id/sum"
/>
<TextView
android:id="#+id/blank"
android:text=" "
android:textSize="25px"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/sum"
/>
<TextView
android:id="#+id/airdate"
android:text="Air Date : "
android:textSize="25px"
android:textColor="#color/black"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/blank"
/>
<TextView
android:id="#+id/blank2"
android:text=" "
android:textSize="25px"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/airdate"
/>
<TextView
android:id="#+id/airtime"
android:text="Air Time : "
android:textSize="25px"
android:textColor="#color/black"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/blank2"
/>
</RelativeLayout>
</FrameLayout>
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#color/darkblue"
android:id="#+id/fourth"
android:layout_below="#id/third"
android:layout_alignParentBottom="true"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Bottom"
android:textSize="30px"
android:textColor="#color/white"
android:layout_gravity="center"
/>
</FrameLayout>
</RelativeLayout>
In the bottom of what? What is your parent layout? If you're using a RelativeLayout, remove the layout_gravity attribute, and add the alignParentBottom="true" attribute instead.
Not sure this is totally correct but I'm working on an similar app with a bunch of frame layouts that get dynamically generated and had to switch to relative layouts to use the android:layout_below="#id/some_id" to 'stack' my layouts. I'm using fragments and it seems to be working well.
Example layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/top_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#drawable/bg">
<!-- Content Foo -->
</RelativeLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/middle_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_below="#id/top_layout"
android:background="#drawable/bg">
<!-- Content Foo -->
</RelativeLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/bottom_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_below="#id/middle_layout"
android:background="#drawable/bg">
<!-- Content Foo -->
</RelativeLayout>
This is full programmability method :
EKRAN MY_EKRAN;
context = getApplicationContext();
MY_EKRAN = new EKRAN( contex );
YOUR_FRAMELAYOUT = findViewById(R.id.PUT_ID_FOR_YOUR_FRAMELAYOUT);
YOUR_FRAMELAYOUT.post(new Runnable() {
#Override
public void run() {
YOUR_FRAMELAYOUT.getLayoutParams().width = MY_EKRAN.W(105);
YOUR_FRAMELAYOUT.getLayoutParams().height = MY_EKRAN.H(10);
// banner.getLayoutParams().width = ( MY_EKRAN.H(10));
// banner.getLayoutParams().width = ( MY_EKRAN.H(10));
YOUR_FRAMELAYOUT.setY( MY_EKRAN.H(90) );
// also like this
// YOUR_FRAMELAYOUT.setLayoutParams(new LinearLayout.LayoutParams( MY_EKRAN.W(100) ,MY_EKRAN.H(30) ));
}
});
Here's ekran class :
public class EKRAN {
DisplayMetrics dm = new DisplayMetrics();
Point size_ = new Point();
static int width;
static int height;
EKRAN(Context CONTEXT_) {
dm = CONTEXT_.getResources().getDisplayMetrics();
int densityDpi = dm.densityDpi;
height = dm.heightPixels;
width = dm.widthPixels;
}
public static int WIDTH() {
return width;
}
public static int HEIGHT(){
return height;
}
public int W( int PER_ ){
return width/100*PER_;
}
public int H( int PER_ ){
return height/100*PER_;
}
//////////////////
//extras
/////////////////
public int GET_PIX_FROM_DP ( float DP_VALUE )
{
return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, DP_VALUE , dm );
}
public int GET_PIX_FROM_DP2 ( float DP_VALUE )
{
float res = DP_VALUE * ( dm.ydpi / 160f);
return (int) res;
}
}

Categories

Resources