Tag: android layout

Android Studio:新创build的目录不出现在文件夹视图中

我正在尝试在/ res目录中创build一个新的文件夹 我添加了一个新的目录 该文件夹即使存在于查找器中,也不会出现在/ res文件夹中 案例和观点我试图再次添加文件夹,我收到一条消息,告诉我它存在。 如果你能build议我能做些什么来解决这个问题,我很乐意! (是的,我已经重新启动了程序以及我的电脑)

微调不包装文本 – 这是一个Android的错误?

如果Spinner项目的文本太长而无法放入一行,则文本不会被打包,而会被截断。 API级别> = 11的情况才是这种情况。 这里是Android 4.2.2 (左)的屏幕截图,它显示了错误的行为和Android 2.3.3 (右),看起来如预期的那样。 android:singleLine="false"在这里就被忽略了。 所以像所有其他的尝试像android:lines , android:minLines等android:minLines似乎比窗口宽度宽得多。 我看到其他人有同样的问题,但没有人能find解决办法。 那么,这是一个系统错误吗? 我不认为操作系统版本之间的这种不一致可能是有意的。 请注意: 有一些答案提出了相对简单的解决scheme。 编写一个自定义Adapter并重写getView()以及getDropDownView() 。 这不是解决scheme,因为在这一点上,仍然存在原始问题:布局如何处理正确的换行? 将下拉视图的TextView包装到父ViewGroup 。 不能使用android:layout_width="match_parent"因为父母的宽度似乎是无限的。 给下拉查看一个固定的宽度。 这不适用于Spinner可以具有的不同的宽度。 当然,没有任何解决scheme是手动将\n的任何地方插入到文本中。 用下面的代码重现: 更新:我也上传了这个作为GitHub上的示例项目: 下载 /res/values/arrays.xml: <string-array name="items"> <item>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt.</item> <item>At vero eos et accusam et justo duo […]

将内容dynamic添加到线性布局?

例如,如果我已经定义了一个垂直方向的根线性布局: main.xml : <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/my_root" android:layout_height="wrap_content" android:layout_width="fill_parent" android:orientation="vertical" <!– I would like to add content here dynamically.–> </LinearLayout> 在根线性布局里面,我想添加多个子线性布局 ,每个子线性布局方向都是水平的 。 有了这些,我最终可以得到一个类似输出的表格。 例如root与子布局如: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/my_root" android:layout_height="wrap_content" android:layout_width="fill_parent" android:orientation="vertical" <!– 1st child (1st row)–> <LinearLayout … android:orientation="horizontal"> <TextView …/> <TextView …/> <TextView …/> </LinearLayout> <!– 2nd child (2nd […]

使用ConstraintLayout均匀地分隔视图

LinearLayout一个常见用途是平均间隔(重量)视图,例如: 你如何使用新的ConstraintLayout实现这样的均匀间隔的视图? ConstraintLayout链接供参考: 博客文章 , I / O会话video

ProgressDialog旋转圈

我想实现像这样的ProgressDialog,没有额外的帧: 但是我得到这个。 我怎么能改变这个? 这是我的ProgressDialog代码。 提前致谢 private ProgressDialog mProgressDialog; ………… mProgressDialog = new ProgressDialog(activity); mProgressDialog.setIndeterminate(false); mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); ………… public class ProgressTask extends AsyncTask <Fragment,Void,Fragment>{ @Override protected void onPreExecute(){ mProgressDialog.show(); } @Override protected Fragment doInBackground(Fragment… arg0) { //my stuff is here } @Override protected void onPostExecute(Fragment result) { mProgressDialog.dismiss(); } }

添加后退button到操作栏

我一直在试图添加一个后退button到操作栏。 我希望我的观点如下所示: 我想添加操作栏左侧的后退button。 我添加了这个代码 ActionBar actionBar = getActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); 但它不起作用。 我怎样才能解决这个问题?

postInvalidate()是做什么的?

Android中的postInvalidate()函数有什么用? 我已经在很多地方看到了这个function。 当我谷歌search,我出来这么多: postInvalidate– 在UI线程上发布一个无效请求 我不知道这里的“无效请求”是什么意思。 有人可以详细解释这里发生了什么?

如何更改Android 5中的默认对话框button文本颜色

我的应用程序中有很多提醒对话框。 这是一个默认的布局,但我正在向对话框添加正面和负面的button。 所以button得到Android 5(绿色)的默认文本颜色。 我试图改变它没有成功。 任何想法如何改变文字颜色? 我的自定义对话框 public class MyCustomDialog extends AlertDialog.Builder { public MyCustomDialog(Context context,String title,String message) { super(context); LayoutInflater inflater = (LayoutInflater) context.getSystemService( Context.LAYOUT_INFLATER_SERVICE ); View viewDialog = inflater.inflate(R.layout.dialog_simple, null, false); TextView titleTextView = (TextView)viewDialog.findViewById(R.id.title); titleTextView.setText(title); TextView messageTextView = (TextView)viewDialog.findViewById(R.id.message); messageTextView.setText(message); this.setCancelable(false); this.setView(viewDialog); } } 创build对话框: MyCustomDialog builder = new MyCustomDialog(getActivity(), "Try Again", […]

ScrollView布局不填满整个屏幕

我得到了两个Fragment的Activity (一个正常的名单)。 正常的Fragment膨胀一个包含LineaLayout (垂直)的LineaLayout ,这个布局包含TextViews 。 ScrollView和layout_width和layout_height是match_parent ,所以我认为应该使用整个屏幕。 但是底部还是有一个“差距”。 我希望你能帮助我。 ScrollView.xml <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/scrollView1" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:id="@+id/LinearLayout1" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/titlescreen_bg" android:orientation="vertical" android:paddingTop="60dp" tools:context=".MainActivity" > <TextView android:id="@+id/tv_headline" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:paddingBottom="60dp" android:paddingTop="60dp" android:textIsSelectable="false" android:textSize="@dimen/fontsize_slogan_titlescreen" /> <TextView android:id="@+id/tv_content" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:paddingBottom="30dp" android:paddingTop="30dp" android:textIsSelectable="false" android:textSize="@dimen/fontsize_slogan_titlescreen" /> </LinearLayout> </ScrollView> 使这个布局膨胀的片段。 package wak.iage.layout; import wak.iage.R; import android.app.Fragment; […]

如何在Android中为Navigation Drawer添加一个分隔符?

我有一个像这个图像的导航抽屉。 我想添加一个部分分隔符(如分隔海王星​​线)。 这似乎很简单,但我无法find任何有用的networking上的事情。 这是我的MainActivity: public class MainActivity extends Activity { private DrawerLayout mDrawerLayout; private ListView mDrawerList; private ActionBarDrawerToggle mDrawerToggle; private CharSequence mDrawerTitle; private CharSequence mTitle; private String[] mPlanetTitles; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mTitle = mDrawerTitle = getTitle(); mPlanetTitles = getResources().getStringArray(R.array.planets_array); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerList = (ListView) findViewById(R.id.left_drawer); // set a […]