Android的获取可见布局的高度编程 [英] Android Get height of the visible layout programmatically
问题描述
我想要得到的可视布局的确切高度编程,因为我在图中所示。我用夏洛克片段活性的含有不同片段的主要活动。我试图通过显示和显示矩阵得到屏幕的高度和宽度,但它给整个屏幕的高度和width.but我想要得到的子活动的唯一可见的视图。请帮助我。在此先感谢。
主要XML (的TabBar的)
< RelativeLayout的
的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT>
< TabHost
机器人:ID =@机器人:ID / tabhost
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT>
<的LinearLayout
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:方向=垂直>
<的FrameLayout
机器人:ID =@机器人:ID / tabcontent
机器人:layout_width =@扪/ fr_layout_width
机器人:layout_height =@扪/ fr_layout_height
机器人:layout_weight =0/>
<的FrameLayout
机器人:ID =@ +安卓ID / realtabcontent
机器人:layout_width =FILL_PARENT
机器人:layout_height =@扪/ fr_layout_height
机器人:layout_weight =1/>
< TabWidget
机器人:ID =@机器人:ID /标签
机器人:layout_width =FILL_PARENT
机器人:layout_height =@扪/ hdpi_tab_layout_height
机器人:layout_weight =0
机器人:背景=@机器人:彩色/透明
机器人:重力=底
机器人:方向=横向/>
< / LinearLayout中>
< / TabHost>
< /android.support.v4.widget.DrawerLayout>
子XML (子活动的XML)
< XML版本=1.0编码=UTF-8&GT?;
<滚动型
的xmlns:机器人=http://schemas.android.com/apk/res/android
的xmlns:工具=http://schemas.android.com/tools
机器人:ID =@ + ID / mainscroll
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
工具:上下文=MainActivity。>
<的LinearLayout
机器人:ID =@ + ID / topliner
机器人:layout_width =match_parent
机器人:layout_height =FILL_PARENT
机器人:方向=垂直
>
< / LinearLayout中>
< /滚动型>
抱歉打扰,我解决我的问题,通过对方的回答得到了一些想法,但我看到一些德precated方法,建议将解决这个问题。
的动作条和的TabBar高度
INT tabHeight = mTabHost.getTabWidget()的getHeight()。
。INT actionbarheight = getSupportActionBar()的getHeight(); // getActionbar()insted的对阿比更大的13比
状态栏的高度
公众诠释getStatusBarHeight(){
INT结果为0;
INT RESOURCEID = getResources()则getIdentifier(status_bar_height,地扪,机器人)。
如果(RESOURCEID大于0){
。结果= getResources()getDimensionPixelSize(RESOURCEID);
}
返回结果;
}
INT statusbarheight = getStatusBarHeight();
获取屏幕尺寸
显示显示= getWindowManager()getDefaultDisplay()。
如果(Build.VERSION.SDK_INT< = Build.VERSION_ codeS.HONEYCOMB_MR2)
{
宽度= display.getWidth(); //德precated
身高= display.getHeight() - (tabHeight + actionbarheight + statusbarheight);
}
其他 {
点尺寸1 =新的点();
display.getSize(尺寸1);
宽度= size1.x;
身高= size1.y - (tabHeight + actionbarheight + statusbarheight); //可见的布局高度
}
I want to get the exact height of the visible layout programmatically as I shown in figure. I used Sherlock fragment activity as main activity which contain different fragments. I tried to get the height and width of the screen through Display and display matrix, but it give whole screen height and width.but i want to get only visible view of the child activity. please help me. thanks in advance.
Main XML(of Tabbar)
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TabHost
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="@dimen/fr_layout_width"
android:layout_height="@dimen/fr_layout_height"
android:layout_weight="0" />
<FrameLayout
android:id="@+android:id/realtabcontent"
android:layout_width="fill_parent"
android:layout_height="@dimen/fr_layout_height"
android:layout_weight="1" />
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="@dimen/hdpi_tab_layout_height"
android:layout_weight="0"
android:background="@android:color/transparent"
android:gravity="bottom"
android:orientation="horizontal" />
</LinearLayout>
</TabHost>
</android.support.v4.widget.DrawerLayout>
child xml (Xml of child Activity)
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/mainscroll"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context=".MainActivity">
<LinearLayout
android:id="@+id/topliner"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
</LinearLayout>
</ScrollView>
Sorry for Disturb , I solved my question for getting some ideas through other answer but i see some deprecated method which is suggested to solve it.
for actionbar And tabbar height
int tabHeight = mTabHost.getTabWidget().getHeight();
int actionbarheight = getSupportActionBar().getHeight();//getActionbar() insted of for Api greater 13 than
height of statusbar
public int getStatusBarHeight() {
int result = 0;
int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
if (resourceId > 0) {
result = getResources().getDimensionPixelSize(resourceId);
}
return result;
}
int statusbarheight = getStatusBarHeight();
for getting screen size
Display display = getWindowManager().getDefaultDisplay();
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.HONEYCOMB_MR2)
{
width = display.getWidth(); // deprecated
height = display.getHeight()- (tabHeight + actionbarheight + statusbarheight );
}
else {
Point size1 = new Point();
display.getSize(size1);
width = size1.x;
height = size1.y - (tabHeight + actionbarheight + statusbarheight);//visible layout height
}
这篇关于Android的获取可见布局的高度编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!