我对LinearLayout,RelativeLayout和AbsoluteLayout之间的区别感到困惑.有人可以告诉我他们之间的确切差异吗?
android android-layout android-linearlayout android-relativelayout android-framelayout
我看到很多应用程序使用全屏图像作为背景.这是一个例子:

我想在一个项目中使用它,到目前为止我发现的最好方法是使用大尺寸的图像,将其放入ImageView并用于android: adjustViewBounds="true"调整边距
问题是如果分辨率非常高的屏幕,图像不足.
我想到的另一个选择是在a中使用图像FrameLayout,使用match_parentin width和heightas作为背景...这会拉伸图像,但我认为结果不是很好.
你会怎么做?
这里我有一个视图分页器活动,它有一个imageview和2个覆盖条.我使用android xml文件布局本身制作了覆盖条.
我的要求就是这样
1)第一次单击视图寻呼机的imageview =显示顶部和底部矩形覆盖栏.2)第二次单击视图寻呼机的imageview =隐藏这些叠加.
这两个都是像android gallary视图类型的功能.
但是,当这时显示这些顶部和底部布局栏时,我只想使用按钮,只需单击此布局中声明的按钮.
但是我没有成功实现这个目标.
问题
1)什么时候top or bottom bar如果我可以点击next or previous按钮而不是它后面的imageview单击触摸事件的事件,我的酒吧变得不可见.2)只需要声明按钮事件3)当我触摸覆盖条时,避免单击视图.
简而言之,当我的顶部和底部图像条出现时,从顶部和底部图像条没有发生图像查看事件.我可以点击imageview,但是当我实际点击下一个或上一个或分享按钮时,我不能点击.
所以这些是我面临的问题,请帮助我.
源代码 :
activity_pager_image.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<RelativeLayout
android:id="@+id/rl_top_overlay"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/slideshow_bar"
android:visibility="gone" >
<TextView
android:id="@+id/tv_top_overlay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:textIsSelectable="false" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/rl_bottom_overlay"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="@drawable/slideshow_bar"
android:visibility="visible" >
<Button
android:id="@+id/btn_left_arrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="35dp"
android:background="@drawable/ic_left_arrow" />
<Button
android:id="@+id/btn_below_share"
style="@style/normalText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="35dp" …Run Code Online (Sandbox Code Playgroud) android android-layout android-gui android-viewpager android-framelayout
我是编程新手.我正在使用Graphical Layout然后当我阅读xml文件时,我看到了FrameLayout.然后我搜索了,但我找不到有用的东西.什么是FrameLayout,它有什么作用?
我正在构建一个UI,它在XML中都是静态定义的.所有这些都在整个地方都有重量,虽然它看起来正确,但我希望看到事情确实具有正确的高度和所有.问题是无论我在哪里调用.getHeight()我的格式布局都得到了0.我在onCreate()和onStart()中都尝试过.一样.也适用于所有UI对象.任何的想法?
package com.app.conekta;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Window;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.Toast;
public class Conekta extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
@Override
public void onStart() {
super.onStart();
}
@Override
public void onResume() {
super.onResume();
FrameLayout fl1 = (FrameLayout) findViewById(R.id.headerFrameLayout);
FrameLayout fl2 = (FrameLayout) findViewById(R.id.footerFrameLayout);
Button b=(Button) findViewById(R.id.searchButton);
Log.d("CONEKTA", String.valueOf(b.getHeight()));
}
}
Run Code Online (Sandbox Code Playgroud)
XML:
<?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" …Run Code Online (Sandbox Code Playgroud) 我需要为我的应用程序实现一个覆盖(半透明)屏幕,类似于Showcase View
我的猜测是FrameLayout用于这个用例,因为它用于将项目堆叠在一起.但我很惊讶地发现上面的库使用了RelativeLayout.
我的问题是什么时候使用FrameLayout,如果不是这样的话?如果我走的FrameLayout路有什么缺点?
对不起,巨大的代码转储,但我真的迷路了.
MyActivity.java onCreate:
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_singlepane_empty);
mFragment = new PlacesFragment();
getSupportFragmentManager().beginTransaction()
.add(R.id.root_container, mFragment)
.commit();
Run Code Online (Sandbox Code Playgroud)
PlacesFragment.java onCreateView:
mRootView = (ViewGroup) inflater.inflate(R.layout.list_content, null);
return mRootView;
Run Code Online (Sandbox Code Playgroud)
注意:mRootView是一个ViewGroup全局,我相信没问题.PlacesFragment是一个ListFragment.
布局:
activity_singlepane_empty.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/root_container"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00f">
<include layout="@layout/actionbar"/>
<!-- FRAGMENTS COME HERE! See match_parent above -->
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
list_content.xml:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/listContainer"
android:background="#990"
>
<ListView android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:drawSelectorOnTop="false" />
<TextView android:id="@id/android:empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/no_data_suggest_connection"/>
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)
问题:正如您所看到的,预期的行为是将上面的空TextView显示在屏幕中心.在Eclipse的设计预览中,没关系.只有当作为片段添加到root_view时,FrameLayout才会填满整个屏幕.
root_container为蓝色,FrameLayout为黄色,请参阅下面的调试目的.黄色窗格不应该填满整个屏幕吗?!?!?!?

android center fragment android-linearlayout android-framelayout
I am building a layout for large screens, that is supposed to consist of 2 different parts, a left one and a right one. For doing that I thought using 2 Fragments is the right choice.
Then I had a look on the example of the navigation with the Master/Detail-Flow. It has a 2-pane layout, where on the right is the navigation, and on the left is the detail view.
但是在那个例子中,与我期望看到的不同,对于细节视图,有一个FrameLayout然后持有a Fragment,而不是Fragment直接.
布局XML看起来像这样(一个例子):
<LinearLayout …Run Code Online (Sandbox Code Playgroud) 我的布局包含一些文本字段,并且背景图像显示在我的活动顶部.我希望背景图像可以缩放以包装内容(不关心宽高比).但是,图像大于内容,因此布局反而包裹背景图像.这是我的原始代码:
<RelativeLayout
android:layout_width="fill_parent"
android:id="@+id/HeaderList"
android:layout_gravity="top"
android:layout_height="wrap_content"
android:background="@drawable/header">
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/NameText"
android:text="Jhn Doe"
android:textColor="#FFFFFF"
android:textSize="30sp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:paddingLeft="4dp"
android:paddingTop="4dp"
/>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textColor="#FFFFFF"
android:layout_alignParentLeft="true"
android:id="@+id/HoursText"
android:text="170 hours"
android:textSize="23sp"
android:layout_below="@+id/NameText"
android:paddingLeft="4dp"
/>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
在搜索了其他一些问题后,我发现了这两个问题:
基于此,我创建了一个带有ImageView的FrameLayout,显示背景.不幸的是,我仍然无法让它工作.我想要的背景图像的高度缩小/扩大W /文观点的大小,但与FrameLayout里,该ImageView的适合的大小的它的父,我无法找到一个办法让母公司适合文本视图布局的大小.这是我更新的代码:
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<ImageView android:src="@drawable/header"
android:layout_width="fill_parent"
android:scaleType="fitXY"
android:layout_height="fill_parent"
/>
<RelativeLayout
android:layout_width="fill_parent"
android:id="@+id/HeaderList"
android:layout_gravity="top"
android:layout_height="wrap_content"
>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/NameText"
android:text="John Doe"
android:textColor="#FFFFFF"
android:textSize="30sp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:paddingLeft="4dp"
android:paddingTop="4dp"
/>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textColor="#FFFFFF"
android:layout_alignParentLeft="true"
android:id="@+id/HoursText"
android:text="170 hours"
android:textSize="23sp"
android:layout_below="@+id/NameText"
android:paddingLeft="4dp"
/>
</RelativeLayout> …Run Code Online (Sandbox Code Playgroud) android background android-linearlayout android-relativelayout android-framelayout
我正在研究Android的导航抽屉.根据我的要求,我要在导航抽屉中显示gridview和项目列表视图.我在布局xml文件中创建了一个linearLayout,并将两个小部件(Grid视图和Listview)放在LinearLayout中.
当我运行该文件时,我收到以下错误:
java.lang.RuntimeException:无法启动活动ComponentInfo {com.example.navigationdrawer3/com.example.navigationdrawer3.MainActivity}:java.lang.ClassCastException:android.widget.FrameLayout $ LayoutParams无法强制转换为android.support.v4. widget.DrawerLayout $的LayoutParams
下面是我的java,logcat和NavigationDrawer布局文件:
MainActivity.java
public class MainActivity extends Activity {
private DrawerLayout mDrawerLayout;
private ListView mDrawerList;
private ActionBarDrawerToggle mDrawerToggle;
private CharSequence mDrawerTitle;
//@SuppressWarnings("unused")
private CharSequence mTitle;
private String[] mGalaxyTitles;
private GridView mDrawerGrid;
private LinearLayout mDrawerLinear;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mTitle = mDrawerTitle = getTitle();
mGalaxyTitles = getResources().getStringArray(R.array.items_array);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerList = (ListView) findViewById(R.id.left_drawer);
mDrawerGrid = (GridView)findViewById(R.id.gridview);
mDrawerLinear =(LinearLayout)findViewById(R.id.linearLayout);
mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
mDrawerGrid.setAdapter(new ImageAdapter(MainActivity.this));
mDrawerList.setAdapter(new ArrayAdapter<String>(this,
R.layout.drawer_list_item, mGalaxyTitles));
mDrawerList.setOnItemClickListener(new DrawerItemClickListener()); …Run Code Online (Sandbox Code Playgroud) android android-layout navigation-drawer drawerlayout android-framelayout
android ×10
background ×2
android-gui ×1
center ×1
drawerlayout ×1
fragment ×1
imageview ×1
java ×1