Tag: android layout

Android平板电脑的布局

我想为Android平板电脑和手机创build不同的布局。 我应该在哪里放置布局资源以便进行区分?

错误:无法find符号variablesabc_ic_ab_back_mtrl_am_alpha

我添加了片段到我的Android Studio项目使用New > Fragment > Fragment (Blank) 。 因此,当我尝试运行时,项目将无法编译,因为它无法parsingR.drawable.abc_ic_ab_back_mtrl_am_alpha toolbar.setNavigationIcon(R.drawable.abc_ic_ab_back_mtrl_am_alpha); 任何想法如何解决这个问题? 它看起来像我也失去了访问android:buttonTint

Android线性布局 – 如何保持在底部的元素?

我有一个TextView ,我想要在垂直排列的元素使用LinearLayout横向活动的底部。 我已经在文本视图上设置了android:gravity="bottom" ,但它仍然只是低于LinearLayout的最后一个元素,正是我不想要的。 有什么build议么?

有人可以解释attr吗?

我正在查看Honeycomb Gallery示例代码( 在这里 ),并尝试在我自己的应用中添加操作项时运行以下代码: <item android:id="@+id/camera" android:title="Camera" android:icon="?attr/menuIconCamera" android:showAsAction="ifRoom" /> 这个游戏正在把我扔?attr 。 有人可以解释这是做什么? 这与drawable有什么关系? 我似乎无法在Google上find任何有用的信息。 还有是我们可以使用的图标,而不是只是menuIconCamera属性的清单或画廊? 谢谢 编辑:我做了更多的环顾四周,发现attrs.xml看起来像这样: <resources> <declare-styleable name="AppTheme"> <attr name="listDragShadowBackground" format="reference" /> <attr name="menuIconCamera" format="reference" /> <attr name="menuIconToggle" format="reference" /> <attr name="menuIconShare" format="reference" /> </declare-styleable> 不幸的是,这让我更加困惑。 这是干什么的?

是否有可能在xml描述中旋转drawable?

我正在创build一个应用程序,可以重复使用的资源(因为button总是相同的,但镜像或旋转)。 我想要使​​用相同的资源,所以我不必添加3个更多的资源,就像原来的,但旋转。 但是我也不想把代码和XML中可以声明的东西混合起来,或者用一个会花费处理时间的matrix进行转换。 我有一个XML中声明的两个状态button。 <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" android:drawable="@drawable/and_card_details_button_down_left_onclick" /> <!– pressed –> <item android:drawable="@drawable/and_card_details_button_down_left" /> <!– default –> </selector> 我想重复使用drawable,因为它将会是相同的,但是旋转了90º和45º,我把这个button分配给drawable。 <Button android:id="@+id/Details_Buttons_Top_Left_Button" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/details_menu_large_button" /> 我知道我可以用RotateDrawable或Matrix来旋转它,但正如我已经解释过的,我不喜欢这种方法。 是否有可能直接在XML上实现,或者你认为这将是最好的方法吗? 把所有的资源,但旋转,旋转他们的代码? —编辑— @dmaxi的答案很好,这是如何将它与一个项目列表:) <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true"> <rotate android:fromDegrees="90" android:toDegrees="90" android:pivotX="50%" android:pivotY="50%" android:drawable="@drawable/and_card_details_button_up_onclick"/> </item> <item> <rotate android:fromDegrees="90" android:toDegrees="90" android:pivotX="50%" android:pivotY="50%" […]

如何以编程方式删除在XML中定义的现有规则?

我有一个相对布局内包含的线性布局。 它在XML文件中设置在另一个线性布局的右侧(这可以正常工作)。 在某些情况下,我想在活动的onCreate期间更改布局的相对位置,所以我需要修改“右边”参数与另一个布局相关。 我试过这个: RelativeLayout.LayoutParams layoutParams; layoutParams = (RelativeLayout.LayoutParams) linearLayoutToMove .getLayoutParams(); layoutParams.addRule(RelativeLayout.RIGHT_OF, R.id.new_ref_LinearLayout); 但它不起作用:o( 任何线索?

我可以在Android中以不同的布局使用相同的ID吗?

我是Android开发新手。 在不同的Layout XML文件中对图像和TextViews使用相同的ID是否正确? 当eclipse为我自动列出它时,它会列出项目中的所有布局variables,它会发生冲突吗? 到目前为止,我还没有注意到在不同的布局中使用相同的ID有任何问题,但我长期关注。

Android微调:在初始化过程中避免onItemSelected调用

我用Spinner和TextView创build了Android应用程序。 我的任务是从TextView中的微调控制器的下拉列表中显示选定的项目。 我在onCreate方法中实现了Spinner,所以当我运行程序的时候,它在TextView显示一个值(在从下拉列表中select一个项目之前)。 我只想从下拉列表中select一个项目后,才显示TextView中的值。 我该怎么做呢? 这是我的代码: import android.app.Activity; import android.os.Bundle; import android.view.View; import android.widget.AdapterView; import android.widget.AdapterView.OnItemSelectedListener; import android.widget.ArrayAdapter; import android.widget.Spinner; import android.widget.TextView; public class GPACal01Activity extends Activity implements OnItemSelectedListener { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Spinner spinner = (Spinner) findViewById(R.id.noOfSubjects); // Create an […]

新的Google即时和Google+卡界面

Google即时和Google+(Android)都使用类似卡片的界面。 我想知道是否有人知道如何在Android上复制这个接口。 他们都有相当有趣的animation显示新卡也; 任何想法都会很棒。

我如何创build一个Android LinearLayout的边框?

我有一个大的布局,一个更小的布局里面。 如何在小布局周围创build线边框?