我在我的 Android 应用程序中使用一个 tablayout,它会膨胀自定义选项卡并用图标设置它们。由于空间不足,其中一个选项卡的文本被截断。我必须使文本非常小才能完全显示。这是我的选项卡布局的设置方式。
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
app:layout_scrollFlags="scroll|enterAlways"
android:layout_width="match_parent"
android:layout_height="@dimen/custom_tab_layout_height"
app:tabMode="fixed"
app:tabGravity="fill" />
Run Code Online (Sandbox Code Playgroud)
自定义选项卡布局如下所示:
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/custom_text"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="?attr/selectableItemBackground"
android:gravity="center"
android:textSize="8dip"
android:textColor="#ffffff"
android:singleLine="true"/>
Run Code Online (Sandbox Code Playgroud)
这是我设置选项卡文本和图标的代码:
TextView tabOne = (TextView)LayoutInflater.From(this).Inflate(Resource.Layout.custom_tab, null);
tabOne.Text = "Home";
tabOne.SetCompoundDrawablesWithIntrinsicBounds(0, Resource.Drawable.homewhite, 0, 0);
tabLayout.GetTabAt(0).SetCustomView(tabOne);
TextView tab2 = (TextView)LayoutInflater.From(this).Inflate(Resource.Layout.custom_tab, null);
tab2.Text = "Inbox";
tab2.SetCompoundDrawablesWithIntrinsicBounds(0, Resource.Drawable.messageWhite, 0, 0);
tabLayout.GetTabAt(1).SetCustomView(tab2);
TextView tab3 = (TextView)LayoutInflater.From(this).Inflate(Resource.Layout.custom_tab, null);
tab3.SetCompoundDrawablesWithIntrinsicBounds(0, Resource.Drawable.upload_icon, 0, 0);
tabLayout.GetTabAt(2).SetCustomView(tab3);
TextView tab4 = (TextView)LayoutInflater.From(this).Inflate(Resource.Layout.custom_tab, null);
tab4.Text = "Notification";
tab4.SetCompoundDrawablesWithIntrinsicBounds(0, Resource.Drawable.notifWhite, 0, 0);
tabLayout.GetTabAt(3).SetCustomView(tab4);
TextView tab5 = (TextView)LayoutInflater.From(this).Inflate(Resource.Layout.custom_tab, null);
tab5.Text = …Run Code Online (Sandbox Code Playgroud) 布局在视图底部有一个 recyclerview 和一个文本编辑器。当我单击编辑器时,键盘弹出并与 recycerview 重叠。我希望在打开键盘时调整 recyclerview 的大小。在我的清单文件中,我有:
<activity android:name=".CommentActivity"
android:label="yourtime"
android:windowSoftInputMode="adjustResize">
</activity>
Run Code Online (Sandbox Code Playgroud)
我的布局是这样的:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/rv"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<LinearLayout
android:orientation="horizontal"
android:minWidth="25px"
android:minHeight="25px"
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="100"
android:layout_alignParentBottom="true">
<EditText
android:inputType="textMultiLine"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="85"
android:id="@+id/commenteditor"
android:hint="Write a comment" />
<ImageButton
android:src="@drawable/arrow"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="15"
android:id="@+id/send"
android:background="#ffff" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
当键盘出现时,如何使列表向上滚动或调整大小?我曾尝试将 recyclerview 封装在 scrollview 中,但这没有用。
这是它的样子:
我希望它看起来像这样:
我该怎么办?
当我使用EF将更改保存到Db时,出现此错误。我正在使用以下代码来挖掘异常:
catch (DbEntityValidationException e)
{
foreach (var eve in e.EntityValidationErrors)
{
Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
eve.Entry.Entity.GetType().Name, eve.Entry.State);
foreach (var ve in eve.ValidationErrors)
{
Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
ve.PropertyName, ve.ErrorMessage);
}
}
throw;
}
Run Code Online (Sandbox Code Playgroud)
eve.ValidationErrors给了我这2条异常消息:1.)flv_url字段是必需的。2.)org_url字段为必填字段。我怀疑我可能传递了null,所以我尝试使用空字符串,但仍然收到此错误。
这是将模型保存到Db中的代码。
DataModel db = new DataModel();
string userName = vid.UserName;
var vid_list = db.videos.Where(v => v.username == userName).OrderByDescending(d => d.date_added).ToList();
var nvid = vid_list[0];
if (nvid != null)
{
nvid.title = vid.Title;
nvid.categories = vid.Categories;
nvid.videofilename = …Run Code Online (Sandbox Code Playgroud) 我正在使用迭代列表的LINQ表达式执行查询,如下所示:
feedVideos.Add(vid.Where(f => f.UserName == friend.Friend_UserName).FirstOrDefault());
Run Code Online (Sandbox Code Playgroud)
如果没有任何对象,则此表达式将空值添加到列表中.我不知道这是不是正常的行为,但是如何在列表中没有任何对象时添加任何内容?